Test instructions
There is an R row in column C, giving the size of the water droplets in n squares. The time limit T is given, which causes the water droplets to burst from the (Sx,sy) position, and when the fly-out waters meet the static water in the lattice, they converge when the aggregate droplet size >4. Ask about the water droplets in the N-position lattice given at t when the output is not burst: 1 The size of the droplets in the lattice. Otherwise the output: 0 blasting time.
Analysis: See code comments.
#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <vector>#include <queue>#include <map>#include <algorithm>#define Read Freopen ("Q.in", "R", stdin)#define LL Long LongConst intMAXN =103;using namespace STD;intdx[]={0,0,1,-1};intdy[]={1,-1,0,0};intR,C,N,T,SI,SJ;structnode{intX,y,dir,time;} NODE[MAXN];intSIZE[MAXN][MAXN],ST[MAXN][MAXN];voidBFsintXintY) {intI Node Cur,pre; Cur.x=x;cur.y=y; Cur.time=0; cur.dir=-1;//means to burst queue<Node>Q Q.push (cur); while(!q.empty ()) {Pre=q.front (); Q.pop ();if(pre.dir>=0)//If not burst, stop or move in the same direction{intTx=pre.x+dx[pre.dir];//Stop or move in the same direction intTy=pre.y+dy[pre.dir]; Cur.x=tx;cur.y=ty; cur.time=pre.time+1;if(tx>=1&& tx<=r && ty>=1&& ty<=c && cur.time<=t) {if(Size[tx][ty])//If there are drops of water blocking{size[tx][ty]++;if(size[tx][ty]==5) {cur.dir=-1; Q.push (cur);//push put it in, and if the water droplets are stationary, you don't have to push.} }Else //If a space is encountered{cur.dir=pre.dir; Q.push (cur); } } }Else //If the burst moves in a burst direction{st[pre.x][pre.y]=pre.time;//Mark Burst timesize[pre.x][pre.y]=0;//Put here is to handle if there are multiple drops flowing to the point at the same time, and the point is already 4 of the situation for(i=0;i<4; i++) {intTx=pre.x+dx[i];intTy=pre.y+dy[i]; Cur.x=tx;cur.y=ty; cur.time=pre.time+1;if(tx>=1&& tx<=r && ty>=1&& ty<=c && cur.time<=t) {if(Size[tx][ty])//If there are drops of water blocking{size[tx][ty]++;if(size[tx][ty]==5) {cur.dir=-1; Q.push (cur);//push put it in, and if the water droplets are stationary, you don't have to push.} }Else //If a space is encountered{cur.dir=i; Q.push (cur); } } } } }}intMain () {//Read; while(~scanf("%d%d%d%d", &r,&c,&n,&t)) {intI,j,sz;memset(Size,0,sizeof(size));memset(St,0,sizeof(ST)); for(i=0; i<n;i++) {scanf("%d%d%d", &node[i].x,&node[i].y,&sz); Size[node[i].x][node[i].y]=sz; }scanf("%d%d", &SI,&SJ); BFS (SI,SJ); for(i=0; i<n;i++) {intTX=NODE[I].X,TY=NODE[I].Y;if(size[tx][ty]==0)cout<<"0"<<st[tx][ty]<<endl;Else cout<<"1"<<size[tx][ty]<<endl; } }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[Search]hdu5336