| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 149286 | 郑雨心 | 螺旋矩阵 | C++ | Time Limit Exceeded | 1000 MS | 272 KB | 548 | 2026-03-08 20:20:00 |
#include <iostream> #include <cstdio> #include <iomanip> using namespace std; int a[15][15]; int main() { int n; cin>>n; int x=1,y=1,s=0; a[x][y]=1; s++; while (s<n*n) { while (y+1<=n&&a[x][y+1]==0){ a[x][++y]=++s; } while (x+1<=n&&a[x+1][y]==0){ a[++x][y]=++s; } while (y-1>=1&&a[x][y-1]==0) { a[x][--y]=++s; } while (x-1<=n&&a[x-1][y]==0){ a[--x][y]=++s; } } for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++){ cout<<setw(4)<<a[i][j]; } cout<<endl; } return 0; }