7 条题解
-
0
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 110; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; int g[N][N]; int n, m; int main() { cin >> n >> m; int d = 2, x = 0, y = m - 1; for (int i = 1; i <= n * m; i ++ ) { g[x][y] = i; int a = x + dx[d], b = y + dy[d]; if(a < 0 || a >= n || b < 0 || b >= m || g[a][b]) { d = (d + 1) % 4; a = x + dx[d], b = y + dy[d]; } x = a, y = b; } for (int i = 0; i < n; i ++ ) { for (int j = 0; j < m; j ++ ) printf("%5d", g[i][j]); cout << endl; } return 0; }
信息
- ID
- 78
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 682
- 已通过
- 175
- 上传者