Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5336
Test instructions: Give you a r*c grid, some of the grid is empty, some have water, and then give an explosion point, from this point to the surrounding burst four water droplets, if the encounter is merged into a whole, if you encounter other droplets directly run past each other, can run a lattice per second, if the amount of water droplets more than 4 burst open, ask t seconds after the state of the grid.
Code:
#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <ctime>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <string>#include <assert.h>#pragma COMMENT (linker, "/stack:1024000000,1024000000")using namespace STD;Const intMAXN = the;intR, c, N, T;intdir[][2] = { {0,0},{1,0},{ -1,0},{0,1},{0,-1} };intS[MAXN][MAXN];//Map, record the number of dropsintANS[MAXN][MAXN];//Record (I,J) The burst time of the locationstructWater//Inquiry n Puddles{intx, y;//coordinates intt;} P[MAXN];structNode//Water droplets{//coordinates, direction intX, Y, dir;intt;};intSX, SY;BOOLIS_OK (intXintY) {if(x<1|| X>r | | y<1|| Y>C)return false;return true;}voidBFS () { queue<node>Q while(!q.empty ()) Q.pop (); node tmp; for(inti =1; I <=4; i++) {tmp.x = SX; TMP.Y = sy; Tmp.dir = i;//direction of movement of water dropletsQ.push (TMP); } node QQ,QQQ; for(intK =1; K <= T; k++) {intLen = Q.size ();if(len = =0) Break; for(intKK =0; KK < len;kk++) {QQ = Q.front (); Q.pop ();intx = qq.x;inty = qq.y;intD = qq.dir;intxx = qq.x + dir[d][0];intyy = Qq.y + dir[d][1];if(Is_ok (xx, yy)) {if(Ans[xx][yy] = = k)Continue;if(S[xx][yy])//have water absorbed{s[xx][yy]++;if(S[xx][yy] >4) {if(Ans[xx][yy] = =0) {Ans[xx][yy] = k; S[XX][YY] =0; } for(inti =1; I <=4; i++) {tmp.x = XX; Tmp.y = yy; Tmp.dir = i;//direction of movement of water dropletsQ.push (TMP); } } }Else //No water to keep walking{tmp.x = xx; Tmp.y = yy; Tmp.dir = D;//direction of movement of water dropletsQ.push (TMP); } } } }return;}intMain () { while(~scanf("%d%d%d%d", &r, &c, &n, &t)) {memset(S,0,sizeof(s));memset(ANS,0,sizeof(ans));intX, y, Z; for(inti =1; I <= N; i++) {scanf("%d%d%d", &x, &y, &z); p[i].x = x; P[i].y = y; S[x][y] = Z; }scanf("%d%d", &SX, &sy); BFS (); for(inti =1; I <= N; i++) {if(Ans[p[i].x][p[i].y])printf("0%d\n", Ans[p[i].x][p[i].y]);Else printf("1%d\n", S[p[i].x][p[i].y]); } }return 0;}
Copyright NOTICE: Reprint please indicate the source.
Hdu 5336 XYZ and Drops "BFS simulation"