XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1126 Accepted Submission(s): 333
Total Submission(s): 1126 Accepted Submission(s): 333
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
模拟十滴水的游戏 输出第T秒的已知水滴状态
要注意两滴水同时打到大小为4的水滴情况 和 bfs返回时重新给答案数组赋值一边水滴状态
模拟十滴水的游戏 输出第T秒的已知水滴状态
要注意两滴水同时打到大小为4的水滴情况 和 bfs返回时重新给答案数组赋值一边水滴状态
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
int n,m,k,t;
int g[105][105];
int has[105][105];
int a[105][105];
int dir[][5]= {{1,0},{-1,0},{0,1},{0,-1}};
struct node
{
int x,y;
int f;
int t;
friend bool operator <(node A,node B)
{
return A.t>B.t;
}
} E[10005];
void init()
{
memset(has,-1,sizeof has);
memset(a,0,sizeof a);
memset(g,0,sizeof g);
}
bool judge(int x,int y)
{
return x>0&&x<=n&&y>0&&y<=m;
}
priority_queue<node>que;
void bfs(int x,int y)
{
while(que.size()) que.pop();
node k;
k.x=x;
k.y=y;
k.t=0;
for(int i=0; i<4; i++)
{
k.f=i;
que.push(k);
}
while(que.size())
{
k=que.top();
que.pop();
k.t++;
k.x+=dir[k.f][0];
k.y+=dir[k.f][1];
if(k.t>t)
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
if(has[i][j]) a[i][j]=g[i][j];
}
return ;
}
if(judge(k.x,k.y))
{
if(!has[k.x][k.y]&&a[k.x][k.y]==k.t) continue;
if(g[k.x][k.y]==4)
{
g[k.x][k.y]=0;
has[k.x][k.y]=0;
a[k.x][k.y]=k.t;
for(int i=0; i<4; i++)
{
k.f=i;
que.push(k);
}
}
else if(g[k.x][k.y])
{
g[k.x][k.y]++;
}
else
{
que.push(k);
}
}
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
if(has[i][j]) a[i][j]=g[i][j];
}
}
int main()
{
while(scanf("%d%d%d%d",&n,&m,&k,&t)!=EOF)
{
init();
int num=0;
for(int i=0; i<k; i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
g[a][b]=c;
E[num].x=a;
E[num++].y=b;
}
int x,y;
scanf("%d%d",&x,&y);
bfs(x,y);
for(int i=0; i<num; i++)
{
node k=E[i];
if(has[k.x][k.y])
printf("1 %d\n",a[k.x][k.y]);
else
printf("0 %d\n",a[k.x][k.y]);
}
}
}