100 Accepted
# | 状态 分数 | 耗时 | 内存占用 |
---|---|---|---|
#1 | Accepted 10 | 2ms | 304 KiB |
#2 | Accepted 10 | 3ms | 504 KiB |
#3 | Accepted 10 | 3ms | 504 KiB |
#4 | Accepted 10 | 2ms | 504 KiB |
#5 | Accepted 10 | 2ms | 500 KiB |
#6 | Accepted 10 | 3ms | 488 KiB |
#7 | Accepted 10 | 2ms | 500 KiB |
#8 | Accepted 10 | 3ms | 512 KiB |
#9 | Accepted 10 | 2ms | 396 KiB |
#10 | Accepted 10 | 2ms | 500 KiB |
代码
#include<bits/stdc++.h>
using namespace std;
int a[101][101];
int fx[2][2]={{-1,0},{0,-1}};
int main()
{
int n;
cin>>n;
int h=n,l=n,p=0,qdl=n;
for(int i=n*n;i>=1;i--)
{
a[h][l]=i;
int xh=h+fx[p][0];
int xl=l+fx[p][1];
if(xh<1||a[xh][xl]!=0) p=!p,h+=fx[p][0],l+=fx[p][1];
else if(xl<1) p=!p,h=n,l=qdl-1,qdl--;
else h=xh,l=xl;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++) cout<<setw(4)<<a[i][j];
cout<<endl;
}
return 0;
}
信息
- 递交者
- 题目
- P369 练63.3 迂回方阵
- 语言
- C++14(O2)
- 代码长度
- 547 Bytes
- 递交时间
- 2025-4-4 17:36:47
- 评测时间
- 2025-4-4 17:36:48
- 分数
- 100
- 总耗时
- 25ms
- 峰值时间
- 3ms
- 峰值内存
- 512 KiB