Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
依然WA#include <cstdio> #include <string.h> using namespace std; char map[10][20],visited[10][20]; int score,ball,bc; #define dfs(x,y) if (x>=0 && x<10 && y>=0 && y<15)if (map[x][y]==c && visited[x][y]==0)s+=f(x,y); int f(int i,int j){ char c; int s; c=map[i][j]; s=1; visited[i][j]=1; dfs(i-1,j) dfs(i+1,j) dfs(i,j+1) dfs(i,j-1) return s; } #define dfs0(x,y) if (x>=0 && x<10 && y>=0 && y<15)if (map[x][y]==c)f0(x,y); void f0(int i,int j){ char c; c=map[i][j]; map[i][j]=0; dfs0(i-1,j) dfs0(i+1,j) dfs0(i,j+1) dfs0(i,j-1) } int findsame(){ memset(visited,0,sizeof(visited)); int x,y,m,r; char c,cc; m=0; for (int i=9;i>=0;i--)for (int j=0;j<15;j++) if (map[i][j])if (visited[i][j]==0){ cc=map[i][j]; r=f(i,j); if (r>m){ x=i;y=j;c=cc;m=r; } } if (m<=1)return 0; bc++; printf("Move %d at (%d,%d): removed %d balls of color %c, got %d points.\n", bc, 10-x,y+1, m, c, (m-2)*(m-2)); score+=(m-2)*(m-2); ball-=m; f0(x,y); return 1; } void showmap(){ for (int i=0;i<10;i++){ for (int j=0;j<15;j++){ if (map[i][j]==0)putchar(' '); else putchar(map[i][j]); } printf("\n"); } } void nextmap(){ int t,s; char q; for (int j=0;j<15;j++){ t=9; for (int i=9;i>=0;i--)if (map[i][j]){ q=map[i][j];map[i][j]=map[t][j];map[t][j]=q; t--; } } s=0; for (int j=0;j<15;j++){ for (int i=t=0;i<10;i++)if (map[i][j])t++; if (t){ for (int i=0;i<10;i++){ q=map[i][j];map[i][j]=map[i][s];map[i][s]=q; } s++; } } } int main() { int T; scanf("%d",&T); for (int t=0;t<T;t++){ for (int i=0;i<10;i++)scanf("%s",map[i]); score=0;ball=150;bc=0; printf("Game %d:\n\n",t+1); while (findsame()){nextmap();/*showmap();*/} if (ball==0)score+=1000; printf("Final score: %d, with %d balls remaining.\n\n",score,ball); } getchar();getchar(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator