神奇的幻方(NOIP2015)(真·纯模拟)
Posted ghostfly233
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了神奇的幻方(NOIP2015)(真·纯模拟)相关的知识,希望对你有一定的参考价值。
这是道SB模拟题,NOIP--难度
直接贴代码
#include<iostream> #include<cstdio> using namespace std; int n,num=1,zong,heng; int f[41][41]; int main(){ scanf("%d",&n); heng=n/2+1; zong=1; while(num<=n*n){ f[heng][zong]=num; if(f[heng+1][zong-1]||((heng+1>n)&&(zong-1==0)))zong++; else if(heng+1>n)heng=1,zong--; else if(zong-1==0)zong=n,heng++; else heng++,zong--; num++; } for(int i=1;i<=n;i++) { for(int j=1;j<n;j++) printf("%d ",f[j][i]); printf("%d\n",f[n][i]); } return 0; }
以上是关于神奇的幻方(NOIP2015)(真·纯模拟)的主要内容,如果未能解决你的问题,请参考以下文章