解题报告 之 HDU5336 XYZ and Drops
Description
XYZ is playing an interesting game called "drops". It is played on a grid.
Each grid cell is either empty, or occupied by a waterdrop. Each waterdrop has a property "size". The waterdrop cracks when its size is larger than 4, and produces 4 small drops moving towards 4 different directions (up, down, left and right).
In every second, every small drop moves to the next cell of its direction. It is possible that multiple small drops can be at same cell, and they won‘t collide. Then for each cell occupied by a waterdrop, the waterdrop‘s size increases by the number of the
small drops in this cell, and these small drops disappears.
You are given a game and a position (, ),
before the first second there is a waterdrop cracking at position (, ).
XYZ wants to know each waterdrop‘s status after seconds,
can you help him?
, , ,
Input
The first line contains four integers , , and . stands
for the numbers of waterdrops at the beginning.
Each line of the following lines
contains three integers , , ,
meaning that the -th
waterdrop is at position (, )
and its size is .
()
The next line contains two integers , .
It is guaranteed that all the positions in the input are distinct.
Multiple test cases (about 100 cases), please read until EOF (End Of File).
Output
lines.
Each line contains two integers , :
If the -th
waterdrop cracks in seconds, , the
time when it cracked.
If the -th
waterdrop doesn‘t crack in seconds, , its
size after seconds.
Sample Input
4 4 5 10 2 1 4 2 3 3 2 4 4 3 1 2 4 3 4 4 4
Sample Output
0 5 0 3 0 2 1 3 0 1
题目大意:有一个n*m的网格,有k个水洼,给出k个水洼的坐标和水量([1,4])。一个水洼水量超过四就立即会向上下左右各发射一个水滴并立即消失,水滴每秒移动一个格子,遇到新的水洼就加入进去,出了边缘就消失。现在在0s时有一个水洼在(x,y)爆裂,问
T 秒后原来那些水洼的信息(爆裂/未爆裂等等)。
分析:一道毫无节操的模拟题,直接模拟每个水滴和水洼就可以了。。。本来还想着优化一下把爆裂的水洼去掉,后来发现太麻烦了就直接上了,结果还是A掉了。每过一秒更新每个水滴和水洼的状态,注意先水滴后水洼,因为水洼可能爆裂产生水滴那么下一秒这些水滴就要移动了。有一个巧妙的点是,判断一个水洼是不是已经消失了用二维数组Size来判断而不是去扫描一遍。
上代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; const int MAXN = 100 + 10; struct wp { int x, y; int state; int t; wp() { } wp( int x, int y, int state, int t ) { this->x = x; this->y = y; this->state = state; this->t = t; } }; struct drop { int x, y; int dir; int state; drop() { } drop( int x, int y, int dir,int state ) { this->x = x; this->y = y; this->dir = dir; this->state = state; } }; int dir[4][2] = { {-1,0},{1,0},{0,-1},{0,1} }; wp p[MAXN]; drop d[MAXN * 10]; int Size[MAXN][MAXN]; int n, m, k, t; bool inline check( int x, int y ) { return 1 <= x&&x <= n && 1 <= y&&y <= m; } int main() { while(scanf( "%d%d%d%d", &n, &m, &k, &t ) == 4) { int x, y, s; memset( Size, 0, sizeof Size ); for(int i = 0; i < k; i++) { scanf( "%d%d%d", &x, &y, &s ); Size[x][y] = s; p[i] = wp( x, y, 1, -1 ); } scanf( "%d%d", &x, &y ); int cnt = 0; for(int i = 0; i < 4; i++) { d[cnt++] = drop( x, y, i, 1 ); } for(int tt = 1; tt <= t; tt++) { for(int i = 0; i < cnt; i++) { if(d[i].state == 0) continue; d[i].x += dir[d[i].dir][0]; d[i].y += dir[d[i].dir][1]; if(!check( d[i].x, d[i].y )) { d[i].state = 0; } if(Size[d[i].x][d[i].y]>0) { Size[d[i].x][d[i].y]++; d[i].state = 0; } } for(int i = 0; i < k; i++) { if(p[i].state == 0)continue; if(Size[p[i].x][p[i].y]>4) { p[i].state = 0; p[i].t = tt; Size[p[i].x][p[i].y] = 0; for(int j = 0; j < 4; j++) { d[cnt++] = drop( p[i].x, p[i].y, j, 1 ); } } } } for(int i = 0; i < k; i++) { printf( "%d %d\n", p[i].state, (p[i].state == 0 ? p[i].t : Size[p[i].x][p[i].y]) ); } } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。