XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 603 Accepted Submission(s): 163
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
Author
XJZX
Source
题意:有一个r 行 c 列的格子,给出n个格子里有水滴的大小。再给出时间限制T,使得水滴从(sx,sy)位置开始爆破,当飞渐的水遇到格子里的静态水时就会聚在一起,当聚集的水滴大小>4时就会爆破。问在T时给定的n个位置格子里的水滴情况,如果没有爆破就输出:1 格子里水滴大小。否则输出:0 爆破的时间。
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
const int MAXN = 105;
struct NODE
{
int x,y,time,e;
};
int n,m,T;
int mapt[MAXN][MAXN],time[MAXN][MAXN];
void bfs(int sx,int sy)
{
int dir[4][2]={1,0,0,1,-1,0,0,-1};
queue<NODE>q;
NODE now,pre;
now.x=sx , now.y=sy ;
now.time=0 , now.e=-1;// e==-1表法需要爆破
q.push(now);
while(!q.empty()){
pre=q.front(); q.pop();
if(pre.e>=0){
now.x=pre.x+dir[pre.e][0];
now.y=pre.y+dir[pre.e][1];
now.time=pre.time+1;
if(now.x>0&&now.x<=n&&now.y>0&&now.y<=m&&now.time<=T){
if(mapt[now.x][now.y]){
mapt[now.x][now.y]++;
if(mapt[now.x][now.y]==5){
now.e=-1;
q.push(now);
}
}
else{
now.e=pre.e;
q.push(now);
}
}
}
else{
time[pre.x][pre.y]=pre.time;
mapt[pre.x][pre.y]=0;
for(int e=0; e<4; e++){
now.x=pre.x+dir[e][0];
now.y=pre.y+dir[e][1];
now.time=pre.time+1;
if(now.x>0&&now.x<=n&&now.y>0&&now.y<=m&&now.time<=T){
if(mapt[now.x][now.y]){
mapt[now.x][now.y]++;
if(mapt[now.x][now.y]==5){
now.e=-1;
q.push(now);
}
}
else{
now.e=e;
q.push(now);
}
}
}
}
}
}
int main()
{
int k , sx,sy ,num;
NODE node[MAXN];
while(scanf("%d%d%d%d",&n,&m,&k,&T)>0)
{
memset(mapt,0,sizeof(mapt));
for(int i=1; i<=k; i++)
{
scanf("%d%d%d",&sx,&sy,&num);
node[i].x=sx;
node[i].y=sy;
mapt[sx][sy]+=num;
}
scanf("%d%d",&sx,&sy);
bfs(sx,sy);
for(int i=1; i<=k; i++)
if(mapt[node[i].x][node[i].y])
printf("1 %d\n",mapt[node[i].x][node[i].y]);
else
printf("0 %d\n",time[node[i].x][node[i].y]);
}
}