题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5336
Problem Description
XYZ is playing an interesting game called "drops". It is played on a r?c 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 (x, y),
before the first second there is a waterdrop cracking at position (x, y).
XYZ wants to know each waterdrop‘s status after T seconds,
can you help him?
1≤r≤100, 1≤c≤100, 1≤n≤100, 1≤T≤10000
Input
The first line contains four integers r, c, n and T. n stands
for the numbers of waterdrops at the beginning.
Each line of the following n lines
contains three integers xi, yi, sizei,
meaning that the i-th
waterdrop is at position (xi, yi)
and its size is sizei.
(1≤sizei≤4)
The next line contains two integers x, y.
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
n lines.
Each line contains two integers Ai, Bi:
If the i-th
waterdrop cracks in T seconds, Ai=0, Bi= the
time when it cracked.
If the i-th
waterdrop doesn‘t crack in T seconds, Ai=1, Bi= its
size after T 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
Author
XJZX
Source
2015 Multi-University Training Contest 4
题意:
在一个n * m 的矩阵中,一共有 num 个大水滴,求在经过了 T 秒后这 num 个大水滴的状态!
在 0 秒时 (x,y) 位置有个水滴开始爆炸,然后生成了四个小水滴分别向上下左右移动,每个大水滴的 Size > 4 就会爆炸,生成向四周移动的小水滴!
PS:
BFS,把每个小水滴压入优先队列里;
代码如下:
#include <cstdio> #include <cstring> #include <queue> #include <algorithm> #include <iostream> using namespace std; #define maxn 1017 int dx[4] = {-1,1,0,0}; int dy[4] = {0,0,-1,1}; struct node { int x, y; int dir; int t; node() {} node(int _x, int _y, int _dir, int _t) { x = _x,y = _y, dir = _dir, t = _t; } bool operator < (const node &time)const { return t > time.t; } }; struct NODE { int x, y; } a[maxn]; int n, m, T; int Size[maxn][maxn]; int time[maxn][maxn]; int judge(int x, int y, int t) { if(x<=0 || x>n || y<=0 || y>m || time[x][y]== t+1) { return 1; } return 0; } void init() { memset(Size, 0, sizeof(Size)); memset(time, -1,sizeof(time)); } void BFS(int x, int y) { priority_queue<node> q; for(int i = 0; i < 4; i++) { q.push(node(x, y, i, 0)); } while(!q.empty()) { node tt = q.top(); if(tt.t >= T) return ; q.pop(); int tx = tt.x + dx[tt.dir]; int ty = tt.y + dy[tt.dir]; if(judge(tx, ty, tt.t)) continue; if(Size[tx][ty] != 0) { if(Size[tx][ty] == 4) { Size[tx][ty] = 0; time[tx][ty] = tt.t+1; for(int i = 0; i < 4; i++) { q.push(node(tx, ty, i, tt.t+1)); } } else { Size[tx][ty]++; } } else { q.push(node(tx, ty, tt.dir, tt.t+1)); } } } int main() { int num; while(~scanf("%d%d%d%d",&n,&m,&num,&T)) { init(); int _size; for(int i = 0; i < num; i++) { scanf("%d%d%d",&a[i].x,&a[i].y,&_size); Size[a[i].x][a[i].y] = _size; } int x, y; scanf("%d%d",&x,&y); BFS(x, y); for(int i = 0; i < num; i++) { if(time[a[i].x][a[i].y] != -1)//爆炸 { printf("0 %d\n",time[a[i].x][a[i].y]); } else { printf("1 %d\n",Size[a[i].x][a[i].y]); } } } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。