1 条题解

  • 1
    @ 2024-1-27 0:57:01

    嗨嗨嗨😄

    ①: 慢慢模拟,上、下、右上、坐(左)下移动后要记得再次判断

    #include<bits/stdc++.h>
    using namespace std;
    int main() {
    	int a[10][10]={1},b,x=0,y=0,i=2;
    	cin>>b;
    	b--;
    	while(&a[x][y]!=&a[b][b]){
    		if(y!=b)
    			a[++y][x]=i++;
    		else
    			a[y][++x]=i++;
    		if(&a[y][x]==&a[b][b])
    			break;
    		while(y!=0&&x!=b)
    			a[--y][++x]=i++;
    		if(x!=b)
    			a[y][++x]=i++;
    		else
    			a[++y][x]=i++;
    		if(&a[y][x]==&a[b][b])
    			break;
    		while(y!=b&&x!=0)
    			a[++y][--x]=i++;
    	}
    	for(int i=0;i<=b;i++){
    		for(int j=0;j<=b;j++)
    			cout<<a[i][j]<<' ';
    		cout<<'\n';
    	}
    	return 0;
    }
    
    

    ②: 范围是n≤10! 所以可以打表👍

    #include<bits/stdc++.h>
    using namespace std;
    int main() {
    	int a;
    	cin>>a;
    	switch(a){
    		case 1:{
    			cout<<R"(1)";
    			break;
    		}
    		case 2:{
    			cout<<R"(1 3
    2 4)";
    			break;
    		}
    		case 3:{
    			cout<<R"(1 3 4
    2 5 8
    6 7 9)";
    			break;
    		}
    		case 4:{
    			cout<<R"(1 3 4 10
    2 5 9 11
    6 8 12 15
    7 13 14 16)";
    			break;
    		}
    		case 5:{
    			cout<<R"(1 3 4 10 11
    2 5 9 12 19
    6 8 13 18 20
    7 14 17 21 24
    15 16 22 23 25)";
    			break;
    		}
    		case 6:{
    			cout<<R"(1 3 4 10 11 21
    2 5 9 12 20 22
    6 8 13 19 23 30
    7 14 18 24 29 31
    15 17 25 28 32 35
    16 26 27 33 34 36)";
    			break;
    		}
    		case 7:{
    			cout<<R"(1 3 4 10 11 21 22
    2 5 9 12 20 23 34
    6 8 13 19 24 33 35
    7 14 18 25 32 36 43
    15 17 26 31 37 42 44
    16 27 30 38 41 45 48
    28 29 39 40 46 47 49)";
    			break;
    		}
    		case 8:{
    			cout<<R"(1 3 4 10 11 21 22 36
    2 5 9 12 20 23 35 37
    6 8 13 19 24 34 38 49
    7 14 18 25 33 39 48 50
    15 17 26 32 40 47 51 58
    16 27 31 41 46 52 57 59
    28 30 42 45 53 56 60 63
    29 43 44 54 55 61 62 64)";
    			break;
    		}
    		case 9:{
    			cout<<R"(1 3 4 10 11 21 22 36 37
    2 5 9 12 20 23 35 38 53
    6 8 13 19 24 34 39 52 54
    7 14 18 25 33 40 51 55 66
    15 17 26 32 41 50 56 65 67
    16 27 31 42 49 57 64 68 75
    28 30 43 48 58 63 69 74 76
    29 44 47 59 62 70 73 77 80
    45 46 60 61 71 72 78 79 81)";
    			break;
    		}
    		case 10:{
    			cout<<R"(1 3 4 10 11 21 22 36 37 55
    2 5 9 12 20 23 35 38 54 56
    6 8 13 19 24 34 39 53 57 72
    7 14 18 25 33 40 52 58 71 73
    15 17 26 32 41 51 59 70 74 85
    16 27 31 42 50 60 69 75 84 86
    28 30 43 49 61 68 76 83 87 94
    29 44 48 62 67 77 82 88 93 95
    45 47 63 66 78 81 89 92 96 99
    46 64 65 79 80 90 91 97 98 100)";
    			break;
    		}
    	}
    	return 0;
    }
    

    暴力出奇迹 打表拿省一🎉️

    • 1

    信息

    ID
    122
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    11
    已通过
    7
    上传者