Simulate, note the case of an even number
1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <iostream>5#include <queue>6#include <stack>7#include <cmath>8#include <algorithm>9#include <malloc.h>Ten using namespacestd; One #defineCLC (A, B) memset (A,b,sizeof (a)) A #defineINF 0x3f3f3f3f - Const intn=10010; - #defineLL Long Long the Const DoubleEPS = 1e-5; - Const DoublePI = ACOs (-1); - intg[1010][1010]; - //Inline int R () { + //int X=0,f=1;char Ch=getchar (); - //While (ch> ' 9 ' | | ch< ' 0 ') {if (ch== '-') F=-1;ch=getchar ();} + //while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} A //return x*f; at // } - intn,x,y; - intmp[ $][ $]; - intMain () - { -scanf"%d",&n); inx =1, y = (n+1)/2; -mp[x][y]=1; to for(intI=2; i<=n*n;i++) + { - if(x==1&&y!=N) thex=n,y++; * Else if(x!=1&&y==N) $X--, y=1;Panax Notoginseng Else if(x==1&&y==N) -X + +; the Else if(!mp[x-1][y+1]) +X--, y++; A Else theX + +; +mp[x][y]=i; - } $ for(intI=1; i<=n;i++) $ { - for(intj=1; j<=n;j++){ - if(j==1) theprintf"%d", Mp[i][j]); - ElseWuyiprintf"%d", Mp[i][j]); the } -printf"\ n"); Wu } - return 0; About}
View Code
NOIP 2015 Magical Magic Square