hdu 5336 XYZ and Drops 【BFS】

来源:互联网 发布:seo查询爱站网 编辑:程序博客网 时间:2024/05/16 06:02

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


Problem Description
XYZ is playing an interesting game called "drops". It is played on a rc 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 (xy), before the first second there is a waterdrop cracking at position (xy). XYZ wants to know each waterdrop's status after Tseconds, can you help him?

1r1001c1001n1001T10000
 

Input
The first line contains four integers rcn and Tn stands for the numbers of waterdrops at the beginning. 
Each line of the following n lines contains three integers xiyisizei, meaning that the i-th waterdrop is at position (xiyi) and its size is sizei. (1sizei4)
The next line contains two integers xy

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 AiBi
If the i-th waterdrop cracks in T seconds, Ai=0Bi= the time when it cracked. 
If the i-th waterdrop doesn't crack in T seconds, Ai=1Bi= 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
2015 Multi-University Training Contest 4


题目大意:玩玩就明白了~

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.csdn.net/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]);            }        }    }}




0 0
原创粉丝点击