记录编号 |
310643 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOIP 2015]神奇的幻方 |
最终得分 |
100 |
用户昵称 |
BillAlen |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.030 s |
提交时间 |
2016-09-22 20:41:30 |
内存使用 |
0.29 MiB |
显示代码纯文本
#include <iostream>
#include <fstream>
using namespace std;
unsigned int n, magicsq[39][39];
unsigned int pointerx, pointery;
inline void movePointer(){
unsigned int px2 = pointerx, py2 = pointery;
if(px2 == 0 && py2 != n - 1){
py2++;
px2 = n - 1;
}else if(py2 == n - 1 && px2 != 0){
px2--;
py2 = 0;
}else if(py2 == n - 1 && px2 == 0){
px2++;
}else if(magicsq[px2-1][py2+1] != 0){
px2++;
}else{
py2++;
px2--;
}
pointerx = px2;
pointery = py2;
}
int main(){
fstream in("2015magic.in", ios::in), out("2015magic.out", ios::out);
in >> n;
pointerx = 0;
pointery = (n-1)/2;
for(unsigned int i = 1; i <= n * n; i++){
magicsq[pointerx][pointery] = i;
movePointer();
}
for(unsigned int i = 0; i < n; i++){
for(unsigned int j = 0; j < n; j++){
out << magicsq[i][j];
if(j != n - 1) out << " ";
}
out << endl;
}
return 0;
}