XYZ and Drops
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1658 Accepted Submission(s): 553
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
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).
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.
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
题目大意:玩玩就明白了~
http://www.4399.com/flash/6356.htm#search1
中文大意:给我们一个r*c的图,给出n个点,玩一个十滴水的游戏,问在t秒之后这n个点最终的状态,针对输出:1 size 表示没有炸开,size表示现在这滴水的大小,0 b,表示在时间b炸开了。
每一滴水最大的size是4。当大于4的时候就会炸开,小水滴相撞没有影响。
一组很容易wa的数据:来自博客:http://blog.youkuaiyun.com/queuelovestack/article/details/47164981
INPUT
4 4 5 100
1 1 4
1 2 3
1 3 4
1 4 4
2 3 4
2 4
AC OUTPUT
1 4
1 4
0 2
0 1
0 1
Wa OUTPUT
0 4
0 3
0 2
0 1
0 1
wa了半天的数据,简单的说就是同时有多个小水滴能够使得大水滴炸开的时候,算作一个小水滴使得这个大水滴炸开。.口述可能说的并不是很清楚,好好想想这组数据就明白了。
思路:
我们从起点出发,如果小水滴碰到了一个size <=3的大水滴,就不再前行。否则如果碰到了一个size为4的大水滴之后炸裂开,push进队列四个方向的小水滴。
在处理刚刚的问题我们加一个特判即可。
AC代码+注释:
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
struct zuobiao
{
int x,y,step,cur;//x.y.时间.方向.
}now,nex,judge[115];
int n,m,k,t;
int map[115][115];//入图
int vis[115][115];//记录时间
int fx[4]={0,0,1,-1};
int fy[4]={1,-1,0,0};
void bfs(int x,int y)
{
memset(vis,0,sizeof(vis));
queue<zuobiao >s;
for(int i=0;i<4;i++)//第一次进去四个.
{
now.x=x;
now.y=y;
now.step=0;//初始化时间为0.
now.cur=i;//初始化四个方向、
s.push(now);
}
while(!s.empty())
{
now=s.front();
s.pop();
for(int i=0;i<4;i++)
{
if(i==now.cur)//找到该水滴该走的方向
{
nex.x=now.x+fx[i];
nex.y=now.y+fy[i];
nex.step=now.step+1;
if(nex.step>t)break;//控制在时间限制内
if(nex.x>=0&&nex.x<n&&nex.y>=0&&nex.y<m)//必须在可行范围内、
{
if(map[nex.x][nex.y]==0)//如果走到的地方没有大水滴
{
if(vis[nex.x][nex.y]==nex.step)continue;//如果走到的地方同时间有其他小水滴使得大水滴炸裂过,这个小水滴相当于没有了
nex.cur=i;
s.push(nex);
}
else//如果走到的地方有大水滴
{
map[nex.x][nex.y]+=1;
if(map[nex.x][nex.y]==5)//如果达到了爆裂的条件
{
map[nex.x][nex.y]=0;//爆裂并且标记并且分成四个小水滴
for(int i=0;i<4;i++)
{
// nex.step=now.step;
nex.cur=i;
s.push(nex);
}
vis[nex.x][nex.y]=nex.step;//标记上这个地方炸裂的时间
}
}
}
}
}
}
}
int main()
{
while(scanf("%d%d%d%d",&n,&m,&k,&t)!=EOF)
{
memset(map,0,sizeof(map));
for(int i=0;i<k;i++)
{
int x,y,w;
scanf("%d%d%d",&x,&y,&w);
x--;
y--;
judge[i].x=x;
judge[i].y=y;
map[x][y]=w;
}
int sx,sy;
scanf("%d%d",&sx,&sy);
sx--;
sy--;
bfs(sx,sy);
for(int i=0;i<k;i++)
{
int x=judge[i].x;
int y=judge[i].y;
if(vis[x][y]!=0)
{
printf("0 %d\n",vis[x][y]);
}
else
{
printf("1 %d\n",map[x][y]);
}
}
}
}
本文介绍了一款名为“十滴水”的游戏模拟算法。玩家在一个r*c网格上放置水滴,每滴水都有一个初始大小。当水滴大小超过4时会分裂成四个小水滴。文章详细解释了游戏规则及模拟过程,并给出了AC代码。
1104

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



