zoj 3810

来源:互联网 发布:我国网络发展现状 编辑:程序博客网 时间:2024/06/05 16:17

构造,5的情况单独输出

#pragma comment(linker, "/STACK:102400000,102400000")#include<iostream>#include<vector>#include<algorithm>#include<cstdio>#include<queue>#include<stack>#include<string>#include<map>#include<set>#include<cmath>#include<cassert>#include<cstring>#include<iomanip>using namespace std;#ifdef _WIN32#define i64 __int64#define out64 "%I64d\n"#define in64 "%I64d"#else#define i64 long long#define out64 "%lld\n"#define in64 "%lld"#endif/************ for topcoder by zz1215 *******************/#define foreach(c,itr)  for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)#define FOR(i,a,b)      for( int i = (a) ; i <= (b) ; i ++)#define FF(i,a)         for( int i = 0 ; i < (a) ; i ++)#define FFD(i,a,b)      for( int i = (a) ; i >= (b) ; i --)#define S64(a)          scanf(in64,&a)#define SS(a)           scanf("%d",&a)#define LL(a)           ((a)<<1)#define RR(a)           (((a)<<1)+1)#define pb              push_back#define pf              push_front#define X               first#define Y               second#define CL(Q)           while(!Q.empty())Q.pop()#define MM(name,what)   memset(name,what,sizeof(name))#define MC(a,b)memcpy(a,b,sizeof(b))#define MAX(a,b)        ((a)>(b)?(a):(b))#define MIN(a,b)        ((a)<(b)?(a):(b))#define read            freopen("out.txt","r",stdin)#define write           freopen("out2.txt","w",stdout)const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;const double oo = 10e9;const double eps = 10e-9;const double pi = acos(-1.0);const int maxn = 111;int n;int a[maxn][maxn];int nowx, nowy;void findr(int temp){int cnt = 0;for (int y = nowy; y <= n; y++){a[nowx][y] = temp;cnt++;}bool ok = false;if (cnt == 1){a[nowx][n - 1] = temp;ok = true;}nowx++;for (int y = n;; y--){a[nowx][y] = temp;cnt++;if (cnt == n){nowy = y - 1;break;}}if (ok) {a[n][2] = a[n - 1][2];}}void findl(int temp){int cnt = 0;for (int y = nowy; y >=2; y--){a[nowx][y] = temp;cnt++;}bool ok = false;if (cnt == 1){a[nowx][3] = temp;ok = true;}nowx++;for (int y = 2;; y++){a[nowx][y] = temp;cnt++;if (cnt == n){nowy = y + 1;break;}}if (ok) {a[n][n] = a[n - 1][n];}}void gao(){for (int x = 1; x <= n; x++){a[x][1] = 1;}for (int x = 1; x <= n / 2; x++){for (int y = x+1; y <= n; y++){if (x % 2){a[x][y] = 2;}else{a[x][y] = 3;}}for (int y = 2; y <= x + 1; y++){if (x % 2) {a[x + 1][y] = 2;}else{a[x + 1][y] = 3;}}}nowx = n / 2 + 1;nowy = n / 2 + 2;int c[3];if ((n / 2) % 2) {c[0] = 3;c[2] = 2;}else{c[0] = 2;c[2] = 3;}c[1] = 4;int step = 0;for (int i = 1; i <= n - 1 - n / 2; i++){if (i % 2){findr(c[step%3]);}else{findl(c[step%3]);}step++;}}int main(){int T;cin >> T;while (T--){cin >>n;if (n == 1) cout << "Y" << endl;else if (n <= 4) cout << "No solution!" << endl;else if (n == 5) {printf("YYYGR\nYGGGR\nYGYYR\nBYYYR\nBBBBR\n");}else{gao();for (int i = 1; i <= n; i++){for (int j = 1; j <= n; j++){if (a[i][j] == 1) {printf("Y");}else if (a[i][j] == 2){printf("G");}else if (a[i][j] == 3){printf("R");}else if (a[i][j] == 4){printf("B");}}cout << endl;}}}return 0;}



0 0
原创粉丝点击