1 条题解
-
0
#include<bits/stdc++.h> using namespace std; int a[40][40], n ; // 模拟题意即可 int main(){ cin >> n ; int y = n / 2 +1 , x = 1 ; for(int i = 1 ; i <= n * n ; i++){ a[x][y] = i ; if( x == 1 && y != n ){ x = n , y ++ ; }else if( x != 1 && y == n ){ x-- , y = 1 ; }else if(x == 1 && y == n ){ x++; }else if(x!= 1 && y != n ){ if( !a[x-1][y+1]){ x-- , y++ ; }else{ x++; } } } for( int i = 1 ; i<= n ; i++){ for( int j = 1 ; j <= n ; j++){ cout<< a[i][j] << " " ; } cout<< endl; } return 0 ; }
- 1
信息
- ID
- 57
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 3
- 标签
- 递交数
- 21
- 已通过
- 18
- 上传者