解题报告 之 HDU5336 XYZ and Drops
Description
XYZ is playing an interesting game called "drops". It is played on a
![](https://i-blog.csdnimg.cn/blog_migrate/3c51388d569cd3032ec5162810b41f00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/11dec1d5d1d09284df5027bbfffe1503.png)
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?
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3c51388d569cd3032ec5162810b41f00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
,
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0df7c7916c37764e51472dfc343a3bf8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
,
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
,
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3c51388d569cd3032ec5162810b41f00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/11dec1d5d1d09284df5027bbfffe1503.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0df7c7916c37764e51472dfc343a3bf8.png)
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 (
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/3c51388d569cd3032ec5162810b41f00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0df7c7916c37764e51472dfc343a3bf8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
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
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
,
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
,
![](https://i-blog.csdnimg.cn/blog_migrate/92438cda8fd536e58435a2ed4320ae9e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8ed78b18ac14a4ecb56630a40fa44c18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/5dd5f6d14d0abf44009e4ddd5a2da8d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/90a60ba2e3ea28a1500ed05c2881e5b1.png)
, meaning that the
-th waterdrop is at position (
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
,
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
) and its size is
![](https://i-blog.csdnimg.cn/blog_migrate/92438cda8fd536e58435a2ed4320ae9e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8ed78b18ac14a4ecb56630a40fa44c18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/5dd5f6d14d0abf44009e4ddd5a2da8d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/90a60ba2e3ea28a1500ed05c2881e5b1.png)
. (
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/92438cda8fd536e58435a2ed4320ae9e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8ed78b18ac14a4ecb56630a40fa44c18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/5dd5f6d14d0abf44009e4ddd5a2da8d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/90a60ba2e3ea28a1500ed05c2881e5b1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
)
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).
![](https://i-blog.csdnimg.cn/blog_migrate/3c51388d569cd3032ec5162810b41f00.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0df7c7916c37764e51472dfc343a3bf8.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
Each line of the following
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/92438cda8fd536e58435a2ed4320ae9e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8ed78b18ac14a4ecb56630a40fa44c18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/5dd5f6d14d0abf44009e4ddd5a2da8d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/90a60ba2e3ea28a1500ed05c2881e5b1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8ed78b18ac14a4ecb56630a40fa44c18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/92438cda8fd536e58435a2ed4320ae9e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8ed78b18ac14a4ecb56630a40fa44c18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/5dd5f6d14d0abf44009e4ddd5a2da8d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/90a60ba2e3ea28a1500ed05c2881e5b1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/92438cda8fd536e58435a2ed4320ae9e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8ed78b18ac14a4ecb56630a40fa44c18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/5dd5f6d14d0abf44009e4ddd5a2da8d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/90a60ba2e3ea28a1500ed05c2881e5b1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4bb0af0ef2d401cfc29af2ba8a54c112.png)
The next line contains two integers
![](https://i-blog.csdnimg.cn/blog_migrate/82e20a3491b6554bca16b2e497c691bd.png)
![](https://i-blog.csdnimg.cn/blog_migrate/dbf44bad0d0ec3ba88d73624b16bfdcc.png)
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
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4b38e3c57678509a1634f8bce1d5cc5e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f55dd9f43dc190d2889d37674d0956c4.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
If the
![](https://i-blog.csdnimg.cn/blog_migrate/8ed78b18ac14a4ecb56630a40fa44c18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4b38e3c57678509a1634f8bce1d5cc5e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2b203c1c015063a750958b22412a78ae.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f55dd9f43dc190d2889d37674d0956c4.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2b203c1c015063a750958b22412a78ae.png)
If the
![](https://i-blog.csdnimg.cn/blog_migrate/8ed78b18ac14a4ecb56630a40fa44c18.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4b38e3c57678509a1634f8bce1d5cc5e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2b203c1c015063a750958b22412a78ae.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f55dd9f43dc190d2889d37674d0956c4.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6a0880b16005c45f1a99e77c70ee111.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2b203c1c015063a750958b22412a78ae.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1f80243d0ee60179b3bfaa08e2d41700.png)
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;
}