100 Accepted
# | 状态 分数 | 耗时 | 内存占用 |
---|---|---|---|
#1 | Accepted 10 | 2ms | 504 KiB |
#2 | Accepted 10 | 2ms | 508 KiB |
#3 | Accepted 10 | 3ms | 504 KiB |
#4 | Accepted 10 | 3ms | 504 KiB |
#5 | Accepted 10 | 3ms | 504 KiB |
#6 | Accepted 10 | 3ms | 504 KiB |
#7 | Accepted 10 | 3ms | 504 KiB |
#8 | Accepted 10 | 3ms | 504 KiB |
#9 | Accepted 10 | 3ms | 532 KiB |
#10 | Accepted 10 | 3ms | 504 KiB |
代码
#include<bits/stdc++.h>
using namespace std;
int a[25][25];
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],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,--qdl,l=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)
- 代码长度
- 496 Bytes
- 递交时间
- 2025-4-4 17:40:38
- 评测时间
- 2025-4-4 17:40:39
- 分数
- 100
- 总耗时
- 26ms
- 峰值时间
- 3ms
- 峰值内存
- 532 KiB