做了前两场虽然有点恶心,但也没今天那么想吐嘈.... 反正是一题未A..不得不承认依旧很菜..
A题,死了命的提示结果错误.... 显然已模拟题.封装 remove 与 maintain 然后print.. 各种情况都考虑,将其后台数据都输出比较.还是未找到错误点在哪里..
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; const int N = 50; char mp[N][N]; int n, m; bool vis[N][N]; bool legal(int x,int y){ if(x>=1&&x<=n&&y>=1&&y<=m) return true; return false; } void maintain(){ for(int c = 1; c <= m; c++){ for(int r = n; r > 1; r--){ if( mp[r][c] == '0' ){ int p = -1; for(int t = r-1; t >= 1; t-- ){ if( mp[t][c] != '0' ){ p = t; break; } } if( p == -1 ) break; else swap( mp[r][c], mp[p][c] ); } } } } bool find(int x,int y){ bool flag = false; // left if( y >= 3 ){ char ch = mp[x][y]; if( (mp[x][y-1]==ch) && (mp[x][y-2]==ch) ){ flag = true; for(int i = y; i >= 1; i--) if( mp[x][i] == ch ) vis[x][i] = true; else break; } } // right if( y+2 <= m ){ char ch = mp[x][y]; if( (mp[x][y+1]==ch) && (mp[x][y+2]==ch) ){ flag = true; for(int i = y; i <= m; i++) if( mp[x][i] == ch ) vis[x][i] = true; else break; } } // up if( x >= 3 ){ char ch = mp[x][y]; if( (mp[x-1][y]==ch) && (mp[x-2][y]==ch) ){ flag = true; for(int i = x; i >= 1; i--) if( mp[i][y] == ch ) vis[i][y] = true; else break; } } // down if( x+2 <= n ){ char ch = mp[x][y]; if( (mp[x+1][y]==ch) && (mp[x+2][y]==ch) ){ flag = true; for(int i = x; x <= n; i++) if( mp[i][y] == ch ) vis[i][y] = true; else break; } } return flag; } bool remove(){ memset(vis,0,sizeof(vis)); bool flag = false; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++){ if( (!vis[i][j]) && (mp[i][j]!='0') ){ if( find(i,j) ) flag = true; } } if( flag ){ for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if( vis[i][j] ) mp[i][j] = '0'; } return flag; } void print(){ for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++) printf("%c", mp[i][j]); puts(""); } } int main(){ freopen("1.in","r",stdin); int T; scanf("%d", &T); while(T--){ scanf("%d%d",&n,&m); for(int i = 1; i <= n; i++) scanf("%s", mp[i]+1 ); maintain(); while( remove() ){ // print(); maintain(); print(); } } return 0; }
B题 . 魔方构造. 坑爹的是竟然还有N=2.... 神一般的构造..看文库 http://wenku.baidu.com/view/02ace38ad0d233d4b14e693f.html 一般人都会..没看估计都不会.....
对于题目中 "对于每个N字图,每行输出N字图的一行,每行中的数字之间用一个或多个空格分开(注意对齐方式需要按最大的那个数字来对齐)", 真心想吐嘈... 这尼码是啥要求啊.所谓最大数字来对齐, 第一 是左还是右啊, 是 按最大的 n*n来, 还是当前一行的最大呢.. 您好歹给点详细说明呗. 对于N=2这种无解的情况也没个说法,该如何处理.....
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; const int N = 110; void gao(int mp[N][N], int n, int c){ int x = 0, y = n/2; mp[x][y] = 1 + c; for(int top = 2; top <= n*n; top++){ int x1 = (x-1+n)%n, y1 = (y+1+n)%n; if( mp[x1][y1] ) x = (x+1+n)%n; else x = x1, y = y1; mp[x][y] = top + c; } } void kao(int mp[N][N], int n){ if( n%4 == 0 ){ for(int i = 0, top = 1; i < n; i++) for(int j = 0; j < n; j++) mp[i][j] = top++; for(int i = 0; i < n; i++){ for(int j = 0; j < n-i; j++){ if( (i==j)||(i+j==n-1) ) continue; swap( mp[i][j], mp[n-1-i][n-1-j] ); } } } } int tmp[N][N]; int A[N][N], B[N][N], C[N][N], D[N][N]; int mp[N][N]; void cao(int n){ int m = n/4; int k = 2*m+1; gao( A, k, 0 ); gao( B, k, k*k ); gao( C, k, 2*k*k ); gao( D, k, 3*k*k ); for(int i = 0; i < k; i++){ int d = (i==k/2)?1:0; for(int j = 0; j < m; j++){ swap( A[i][j+d], D[i][j+d] ); } } for(int i = 0; i < k; i++){ for(int j = 0; j < m-1; j++){ swap( C[i][k-1-j], B[i][k-1-j] ); } } for(int i = 0; i < k; i++) for(int j = 0; j < k; j++){ mp[i][j] = A[i][j]; mp[i][j+3] = C[i][j]; mp[i+3][j] = D[i][j]; mp[i+3][j+3] = B[i][j]; } } int n; void print(int x){ int la = 0, lb = 0, t = n*n; while( t ) la++, t /= 10; t = x; while( t ) lb++, t /= 10; printf("%d", x); for(int i = lb; i < la; i++) printf(" "); } int main(){ while( scanf("%d", &n), n ){ memset( mp, 0, sizeof(mp)); if( n == 2 ){ continue; } if( n&1 ) gao(mp, n, 0); else if( n%4 == 0 ) kao(mp, n); else cao( n ); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if( j != 0 ) printf(" "); //printf("%d", mp[i][j] ); print( mp[i][j] ); } puts(""); } puts(""); } return 0; }
C题, 不知道啥题..不过 岛娘A掉了.. Orz...
总结, 完美世界真心坑..好想知道有多少人在参加这个........ -_-!!!