题目描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
如下图所示,小明用从 11 开始的正整数“蛇形”填充无限大的矩阵。
1 2 6 7 15 ...
3 5 8 14 ...
4 9 13 ...
10 12 ...
11 ...
...
容易看出矩阵第二行第二列中的数是 55。请你计算矩阵中第 2020 行第 2020 列的数是多少?
运行限制
- 最大运行时间:1s
- 最大运行内存: 128M
#include<bits/stdc++.h>
using namespace std;
/*
1 2 6 7 15 ...
3 5 8 14 ...
4 9 13 ...
10 12 ...
11 ...
...*/
int n[21][21],cnt=1,x,y;
int main(){
n[0][0]=1;
while(!n[19][19]){
n[x][++y]=++cnt;
while(y){
n[++x][--y]=++cnt;
}
n[++x][y]=++cnt;
while(x){
n[--x][++y]=++cnt;
}
}
cout<<n[19][19];
}