HDU 5336 XYZ and Drops(BFS)

XYZ and Drops

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


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 T  seconds, 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
 

Author
XJZX
 

Source




#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<queue>

using namespace std;

int r,c,n,pt;
int mp[101][101];

struct node
{
    int xx;
    int yy;
    int tt;
    int ll;
    int dd;
    bool operator < (const node &px) const {
        return tt>px.tt;//最小值优先
    }
};

void BFS(int x,int y)
{
    priority_queue<node>q;
    while(!q.empty())
    {
        q.pop();
    }
    struct node t,f;
    for(int i=-1; i<=1; i++)
    {
        for(int j=-1; j<=1; j++)
        {
            if(i!=j && (abs(i-j)<=1))
            {
                t.xx = x;
                t.yy = y;
                t.tt = 0;
                t.dd = i;
                t.ll = j;
                if(t.xx<=r && t.yy<=c && t.xx>0 && t.yy>0)
                {
                    q.push(t);
                }
            }
        }
    }
    while(!q.empty())
    {
        t = q.top();
        q.pop();
        f.xx = t.xx + t.dd;
        f.yy = t.yy + t.ll;
        f.tt = t.tt + 1;
        if(f.xx<=r && f.yy<=c && f.xx>0 && f.yy>0)
        {
            if(mp[f.xx][f.yy]>0 && f.tt<=pt)
            {
                mp[f.xx][f.yy] += 1;
            }
            else
            {
                if(mp[f.xx][f.yy]<0 && f.tt == -mp[f.xx][f.yy])
                {

                }
                else if(f.tt<=pt)
                {
                    f.ll = t.ll;
                    f.dd = t.dd;
                    q.push(f);
                }
            }
            if(mp[f.xx][f.yy]>4)
            {
                mp[f.xx][f.yy] = -1 * f.tt;
                for(int i=-1; i<=1; i++)
                {
                    for(int j=-1; j<=1; j++)
                    {
                        if(i!=j && (abs(i-j)<=1))
                        {
                            struct node aa;
                            aa.xx = f.xx;
                            aa.yy = f.yy;
                            aa.tt = f.tt;
                            aa.ll = j;
                            aa.dd = i;
                            if(aa.xx<=r && aa.yy<=c && aa.xx>0 && aa.yy>0 && aa.tt<=pt)
                            {
                                q.push(aa);
                            }
                        }
                    }
                }
            }
        }
    }
}

int main()
{
    while(scanf("%d%d%d%d",&r,&c,&n,&pt)!=EOF)
    {
        int pl[110],pr[110];
        int x,y,z;
        memset(mp,0,sizeof(mp));
        for(int i=0; i<n; i++)
        {
            scanf("%d%d%d",&x,&y,&z);
            pl[i] = x;
            pr[i] = y;
            mp[x][y] = z;
        }
        scanf("%d%d",&x,&y);
        BFS(x,y);
        for(int i=0; i<n; i++)
        {
            if(mp[pl[i]][pr[i]]>0)
            {
                printf("1 %d\n",mp[pl[i]][pr[i]]);
            }
            else if(mp[pl[i]][pr[i]]<0)
            {
                printf("0 %d\n",-mp[pl[i]][pr[i]]);
            }
        }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶孤心丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值