hdu5334 XYZ and Drops(BFS)

XYZ and Drops

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2111    Accepted Submission(s): 730


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 ( x y), before the first second there is a waterdrop cracking at position ( x y). XYZ wants to know each waterdrop's status after  Tseconds, can you help him?

1r100 1c100 1n100 1T10000
 

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. ( 1sizei4)
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.
 

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
题意:十滴水游戏,当一个格子的水滴>4就爆炸,分成上下左右的四个水滴,求t秒时,每个格子的状态

根据时间模拟每个水滴即可

注意:多个水滴相同时间到达一个原本含有水滴的位置,比如一个位置原本有4滴水,然后有2滴水同时到达,此时他是从6滴水的状态爆破成4滴水(也就是注意“相同时间“的水滴)

#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int n,m;
struct node
{
    node() {}
    node(int a,int b,int c,int d)
    {
        x=a,y=b,t=c,op=d;
    }
    int x,y,t,op;
    bool friend operator <(node A,node B)
    {
        return A.t>B.t;
    }
} ;
struct edge
{
    int x,y;
} e[105];
int go[4][2]= {1,0,0,1,-1,0,0,-1};
int g[105][105],re[105][105],ans[105];
void bfs(int x,int y,int s)
{
    priority_queue<node>q;
    //优先队列可以保证每次选取时间最小的水滴
    q.push(node(x,y,0,4));
    while(!q.empty())
    {
        node u=q.top();
        q.pop();
        //状态为4的水滴表示需要爆破
        if(u.op==4)
        {
            ans[re[u.x][u.y]]=u.t;
            g[u.x][u.y]=0;
            for(int i=0; i<4; i++)
                q.push(node(u.x,u.y,u.t,i));
        }
        else
        {
            if(u.t>=s)continue;
            int tx=go[u.op][0]+u.x;
            int ty=go[u.op][1]+u.y;
            if(!(tx>=1&&tx<=n&&ty>=1&&ty<=m))continue;
            if(g[tx][ty])
            {
                //此处如此处理可将需爆破的水滴只入队一次,且还能继续更新相同时间的水滴状态(注意里说的那种情况)
                if(g[tx][ty]==4)q.push(node(tx,ty,u.t+1,4));
                g[tx][ty]++;
            }
            else
                q.push(node(tx,ty,u.t+1,u.op));
        }
    }
}
int main()
{
    int t,x,y,k,num;
    while(cin>>n>>m>>k>>t)
    {
        mem(ans,0);
        mem(g,0);

        for(int i=1; i<=k; i++)
        {
            cin>>e[i].x>>e[i].y>>num;
            g[e[i].x][e[i].y]=num;
        }
        cin>>x>>y;
        bfs(x,y,t);
        for(int i=1; i<=k; i++)
        {
            if(!ans[i])
                printf("1 %d\n",g[e[i].x][e[i].y]);
            else
                printf("0 %d\n",ans[i]);
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值