HDU 4527
搞了好久,发现自己是想法没错的,错在输入,必须是while(){}
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> using namespace std; struct Water{ int px,py; int dirx,diry; Water(){} Water(int x,int y,int dx,int dy){px=x,py=y;dirx=dx,diry=dy;} }que[500000]; struct Posover{ int x,y; Posover(int tx,int ty){x=tx,y=ty;} Posover(){} }; vector<Posover>vec; int head,tail; int map[6][6]; void work(int x,int y){ map[x-1][y-1]++; if(map[x-1][y-1]>=5){ map[x-1][y-1]=0; que[tail++]=Water(x-1,y-1,0,-1); que[tail++]=Water(x-1,y-1,0,1); que[tail++]=Water(x-1,y-1,1,0); que[tail++]=Water(x-1,y-1,-1,0); } int sz; vec.clear(); int cnt=0; while(head<tail){ sz=tail-head; cnt++; while(sz--){ int tx=que[head].px+que[head].dirx; int ty=que[head].py+que[head].diry; if(tx>=0&&tx<=5&&ty>=0&&ty<=5){ if(map[tx][ty]>0){ map[tx][ty]++; if(map[tx][ty]==5){ vec.push_back(Posover(tx,ty)); } } else{ que[tail++]=Water(tx,ty,que[head].dirx,que[head].diry); } } head++; } int vsz=vec.size(); for(int i=0;i<vsz;i++){ map[vec[i].x][vec[i].y]=0; que[tail++]=Water(vec[i].x,vec[i].y,0,1); que[tail++]=Water(vec[i].x,vec[i].y,0,-1); que[tail++]=Water(vec[i].x,vec[i].y,1,0); que[tail++]=Water(vec[i].x,vec[i].y,-1,0); } vec.clear(); } // cout<<cnt<<endl; } int main(){ while(scanf("%d",&map[0][0])!=EOF){ int j; for(int i=0;i<6;i++){ for(i==0?j=1:j=0;j<6;j++) scanf("%d",&map[i][j]); } int nop,x,y; scanf("%d",&nop); while(nop--){ tail=head=0; scanf("%d%d",&x,&y); if(x>=1&&x<=6&&y>=1&&y<=6) work(x,y); } for(int i=0;i<6;i++){ printf("%d",map[i][0]); for(int j=1;j<6;j++){ printf(" %d",map[i][j]); } printf("\n"); } printf("\n"); } return 0; }