XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 505 Accepted Submission(s): 122
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 Tseconds, 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 Tseconds, 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
Author
XJZX
Source
解题:直接模拟爆炸情况。。。
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 520; 4 const int dir[4][2] = {-1,0,0,-1,1,0,0,1}; 5 int mp[maxn][maxn],r,c,n,T,x,y; 6 struct waterdrop { 7 int x,y,sz,btime; 8 bool crack; 9 waterdrop(int a = 0,int b = 0,int c = 0,int d = 0) { 10 x = a; 11 y = b; 12 sz = c; 13 btime = d; 14 } 15 } wp[maxn]; 16 struct drop { 17 int x,y,time,o; 18 drop(int a = 0,int b = 0,int c = 0,int d = 0) { 19 x = a; 20 y = b; 21 time = c; 22 o = d; 23 } 24 }; 25 queue<drop>q; 26 bool isIn(int x,int y) { 27 return x > 0 && x <= r && y > 0 && y <= c; 28 } 29 void bfs() { 30 for(int i = 0; i < 4; ++i) 31 q.push(drop(x,y,0,i)); 32 while(!q.empty()) { 33 drop cur = q.front(); 34 q.pop(); 35 if(cur.time >= T) return; 36 int nx = cur.x + dir[cur.o][0]; 37 int ny = cur.y + dir[cur.o][1]; 38 if(!isIn(nx,ny)) continue; 39 int idx = mp[nx][ny]; 40 if(idx == -1 || wp[idx].crack && wp[idx].btime != cur.time+1) q.push(drop(nx,ny,cur.time+1,cur.o)); 41 else if(!wp[idx].crack) { 42 wp[idx].sz++; 43 if(wp[idx].sz > 4) { 44 wp[idx].crack = true; 45 wp[idx].btime = cur.time+1; 46 for(int k = 0; k < 4; ++k) 47 q.push(drop(wp[idx].x,wp[idx].y,cur.time+1,k)); 48 } 49 } 50 } 51 } 52 int main() { 53 while(~scanf("%d%d%d%d",&r,&c,&n,&T)) { 54 memset(mp,-1,sizeof mp); 55 while(!q.empty()) q.pop(); 56 for(int i = 0; i < n; ++i) { 57 scanf("%d%d%d",&wp[i].x,&wp[i].y,&wp[i].sz); 58 wp[i].crack = false; 59 mp[wp[i].x][wp[i].y] = i; 60 if(wp[i].sz > 4) { 61 wp[i].crack = true; 62 wp[i].btime = 0; 63 for(int k = 0; k < 4; ++k) 64 q.push(drop(wp[i].x,wp[i].y,0,k)); 65 } 66 } 67 scanf("%d%d",&x,&y); 68 bfs(); 69 for(int i = 0; i < n; ++i) 70 printf("%d %d ",!wp[i].crack,wp[i].crack?wp[i].btime:wp[i].sz); 71 } 72 return 0; 73 }