题意:类似十滴水游戏,每个水滴的最大饱和值为4,超过4就会向上下左右弹出值为1的水滴,开始时会在某个位置有水滴裂开,问T秒后,原先的固定水滴的状态,如果裂开则输出0和裂开时的时间, 否则输出1和当前水滴的值
思路:用BFS就可以,注意会有同时多颗水滴同时到达一颗已经达到4值的固定水滴处,这样该固定水滴会裂开,但射向它的水滴也会立即消失。水滴的飞溅期间不会互相融合,碰到固定的水滴就被吸收。
XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1521 Accepted Submission(s): 500
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
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).
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.
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#include <stdio.h> #include <queue> #include <string.h> using namespace std; int map[105][105][5], p[105][5]; bool vis[105][105]; int r, c, X, Y; int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0}; struct node { int x, y, dir, Time; bool operator <(const node a) const{ return Time > a.Time; } }; int judge(int x, int y) { if(x >= 0&&x < r&&y >= 0&&y < c) return 1; return 0; } void bfs(int T) { priority_queue<node> q; node start; start.x = X - 1; start.y = Y - 1; if(vis[start.x][start.y] == 1) { vis[start.x][start.y] = 0; map[start.x][start.y][1] = 0; } start.Time = 0; start.dir = 0, q.push(start); start.dir = 1, q.push(start); start.dir = 2, q.push(start); start.dir = 3, q.push(start); node now, next; while(!q.empty()) { now = q.top(); q.pop(); int xx, yy, ti; xx = now.x + dx[now.dir]; yy = now.y + dy[now.dir]; ti = now.Time + 1; if(judge(xx, yy)&&ti <= T) { if(vis[xx][yy] == 1) map[xx][yy][0]++; next.x = xx; next.y = yy; next.Time = ti; if(map[xx][yy][0] > 4&&vis[xx][yy] == 1) { next.dir = 0, q.push(next); next.dir = 1, q.push(next); next.dir = 2, q.push(next); next.dir = 3, q.push(next); vis[xx][yy] = 0;//状态 map[xx][yy][1] = ti;//时间 } else if(vis[xx][yy] == 0&&map[xx][yy][1] == ti); else if(vis[xx][yy] == 0) { next.dir = now.dir; q.push(next); } } } } int main() { int n, t, s, i; while(scanf("%d %d %d %d", &r, &c, &n, &t) != EOF) { memset(map, 0, sizeof(map)); memset(vis, 0, sizeof(vis)); memset(p, 0, sizeof(p)); for(i = 0;i < n;i++) { scanf("%d %d %d", &X, &Y, &s); map[X - 1][Y - 1][0] = s; vis[X - 1][Y - 1] = 1; p[i][0] = X - 1, p[i][1] = Y - 1; } scanf("%d %d", &X, &Y); bfs(t); for(i = 0;i < n;i++) { if(vis[p[i][0]][p[i][1]] == 1) printf("1 %d\n", map[p[i][0]][p[i][1]][0]); if(vis[p[i][0]][p[i][1]] == 0) printf("0 %d\n", map[p[i][0]][p[i][1]][1]); } } return 0; }