XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 736 Accepted Submission(s): 203
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
直接代码:
#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include <algorithm>
#include <queue>
using namespace std;
int Size[110][110];
bool vis[110][110];
int r, c, n ,T;
int dir[4][2] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
int dx[10010], dy[10010];
int time[110][110];
int crash[110][110];
struct P
{
int x, y, dis, t;
}now;
queue <P> ac;
bool ok(int x, int y)
{
if(x >= 1 && x <= r && y >= 1 && y <= c)
return true;
else
return false;
}
int main()
{
while(~scanf("%d%d%d%d", &r, &c, &n, &T))
{
memset(Size, 0, sizeof(Size));
memset(vis, 0, sizeof(vis));
memset(crash, -1, sizeof(crash));
for(int i=0; i<n; i++)
{
scanf("%d%d", &dx[i], &dy[i]);
scanf("%d", &Size[dx[i]][dy[i]]);
vis[dx[i]][dy[i]] = true;
}
int sx, sy;
scanf("%d%d", &sx, &sy);
Size[sx][sy] = 5;
vis[sx][sy] = true;
ac.push((P){sx, sy, 0, 0});
while(!ac.empty())
{
now = ac.front();
ac.pop();
int x = now.x, y = now.y, dis = now.dis, t = now.t;
if(crash[x][y] == t) continue;
if(vis[x][y])
{
Size[x][y]++;
if(Size[x][y] > 4)
{
crash[x][y] = t;
vis[x][y] = false;
time[x][y] = t;
t = t + 1;
for(int i = 0; i < 4; i++)
{
int xx = x + dir[i][0], yy = y + dir[i][1];
if(ok(xx, yy) && t <= T)
{
ac.push((P){xx, yy, i, t});
}
}
}
}
else
{
x = x + dir[dis][0], y = y + dir[dis][1], t = t + 1;
if(ok(x, y) && t <= T)
ac.push((P){x, y, dis, t});
}
}
for(int i=0; i<n; i++)
{
if(vis[dx[i]][dy[i]])
{
printf("1 %d\n", Size[dx[i]][dy[i]]);
}
else
{
printf("0 %d\n", time[dx[i]][dy[i]]);
}
}
}
return 0;
}
本文介绍了一个名为Drops的游戏模拟算法。游戏在一个r*c的网格上进行,每个网格单元可能为空或者包含一滴水,每滴水有一个大小属性。当水滴的大小超过4时,它会分裂成四个小水滴向四个方向移动。每秒每个小水滴向指定方向移动一个单位距离,并可能与其他小水滴或原有水滴融合增加其大小。文章提供了游戏模拟的具体实现代码。

1104

被折叠的 条评论
为什么被折叠?



