Topic Links:
Hdu 5336 XYZ and Drops
Title Description:
There is a n*m lattice matrix, in some small lattice there may be some water droplets, each small droplets have a size. Now, the game began, in a designated empty small lattice inside there will be a burst of water droplets, the next side respectively upward, down, left and right four directions to launch a small water droplets, (small water droplets with water droplets, small water droplets no size), when the small water droplets to a lattice, If the lattice is empty or if there are other small water droplets at the same time to the lattice, the motion trajectory of the small water droplets is not affected. However, the water droplets will be absorbed when the water drops, and the water droplets will increase by 1 when they absorb a small water droplet size. For the balance of all things, water droplets larger than 4 will burst into small droplets around. Ask for the status of each water droplet after the T-time.
Problem Solving Ideas:
is the BFS simulation of small water droplets movement of the state is OK, the game has been card test instructions.
1#include <queue>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7 Const intMAXN = the;8 intdir[4][2] = {1,0, -1,0,0,1,0,-1};9 structnodeTen{//coordinates, direction of movement, time of movement One intx, Y, dir, t; A }; - intmaps[2][MAXN][MAXN], point[maxn][2]; - intR, c, x, Y, T; the - voidBFS () - { -Queue <node>Q; + node p, q; -p.x =x; +P.Y =y; AP.dir =4; atP.T =0; - Q.push (p); - while(!q.empty ()) - { -p =Q.front (); - Q.pop (); in if(P.T >=t) - return ; to if(P.dir = =4) + { - for(intI=0; i<4; i++) the { *q.x = p.x + dir[i][0]; $Q.Y = p.y + dir[i][1];Panax NotoginsengQ.dir =i; -q.t = p.t +1; the if(0>=q.x| | Q.x>r | |0>=q.y| | Q.y>c) + Continue; A if(maps[1][Q.X][Q.Y] = =q.t) the Continue; + if(!maps[0][q.x][q.y]) - Q.push (Q); $ Else $ { -maps[0][Q.X][Q.Y] + +; - if(maps[0][Q.X][Q.Y] >4) the { -maps[1][Q.X][Q.Y] =q.t;Wuyimaps[0][Q.X][Q.Y] =0; theQ.dir =4; - Q.push (Q); Wu } - } About } $ } - Else - { -q.x = p.x + dir[p.dir][0]; AQ.Y = p.y + dir[p.dir][1]; +Q.dir =P.dir; theq.t = p.t +1; - if(0>=q.x| | Q.x>r | |0>=q.y| | Q.y>c) $ Continue; the if(maps[1][Q.X][Q.Y] = =q.t) the Continue; the if(!maps[0][q.x][q.y]) the Q.push (Q); - Else in { themaps[0][Q.X][Q.Y] + +; the if(maps[0][Q.X][Q.Y] >4) About { themaps[1][Q.X][Q.Y] =q.t; themaps[0][Q.X][Q.Y] =0; theQ.dir =4; + Q.push (Q); - } the }Bayi } the the } - } - intMain () the { the intN, S; the while(SCANF ("%d %d%d%d", &r, &c, &n, &t)! =EOF) the { -memset (Maps,0,sizeof(maps)); the for(intI=0; i<n; i++) the { thescanf (" %d%d%d", &x, &y, &s);94point[i][0] =x; thepoint[i][1] =y; themaps[0][x][y] =s; the }98scanf ("%d%d", &x, &y); About BFS (); - for(intI=0; i<n; i++)101 {102x = point[i][0];103y = point[i][1];104 if(maps[0][x][y] = =0) theprintf ("0%d\n", maps[1][x][y]);106 Else107printf ("1%d\n", maps[0][x][y]);108 }109 } the return 0;111}
Hdu 5336 XYZ and Drops (BFS simulation)