HDU 5336 XYZ and Drops

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5336



题意:有一个n*m的平面,平面上有若干个大小为1~4的水滴,当一个水滴碰到一个水珠后大小加1并且水珠消失,一旦水滴大小超过4之后会变成4个水珠向四个方向炸开,现在(x,y)有一个炸开的水滴,水珠1s移动一格且互不干扰,问t秒之后平面上的水滴状态


思路:蛮简单的bfs,判断水珠碰到水滴后是消失还是炸开,注意一下1个以上的水珠同时到达一个水滴的情况就好


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;

struct Node
{
    int x,y,t,f;
}st;

int mp[130][130],sta[130][130];
int sx[130],sy[130];
int chx[5]={1,0,-1,0},chy[5]={0,1,0,-1};
int n,m,k,t;
queue <Node> que;

void bfs()
{
    for (int i=0;i<4;i++)
    {
        int xx=st.x+chx[i];
        int yy=st.y+chy[i];
        if (xx<=0 || xx>n || yy<=0 || yy>m) continue;
        Node nxt;
        nxt.x=xx;
        nxt.y=yy;
        nxt.t=1;
        nxt.f=i;
        que.push(nxt);
    }
    while (!que.empty())
    {
        Node now=que.front();
        que.pop();

        if (mp[now.x][now.y]!=0)
        {
            if (mp[now.x][now.y]==4)
            {
                mp[now.x][now.y]=0;
                sta[now.x][now.y]=now.t;
                for (int i=0;i<4;i++)
                {
                    int xx=now.x+chx[i];
                    int yy=now.y+chy[i];
                    if (xx<=0 || xx>n || yy<=0 || yy>m) continue;
                    Node nxt;
                    nxt.x=xx;
                    nxt.y=yy;
                    nxt.t=now.t+1;
                    nxt.f=i;
                    if (nxt.t<=t)
                        que.push(nxt);
                }
            }
            else
            {
                mp[now.x][now.y]++;
            }
        }
        else
        {
            int xx=now.x+chx[now.f];
            int yy=now.y+chy[now.f];
            if (now.t==sta[now.x][now.y]) continue;
            if (xx<=0 || xx>n || yy<=0 || yy>m) continue;
            Node nxt;
            nxt.x=xx;
            nxt.y=yy;
            nxt.t=now.t+1;
            nxt.f=now.f;
            if (nxt.t<=t)
                que.push(nxt);
        }

    }
}

int main()
{

    while (scanf("%d%d%d%d",&n,&m,&k,&t)!=EOF)
    {
        while (!que.empty())
            que.pop();
        memset(mp,0,sizeof(mp));
        memset(sta,0,sizeof(sta));
        for (int i=0;i<k;i++)
        {
            int x,y,num;
            scanf("%d%d%d",&x,&y,&num);
            sx[i]=x;
            sy[i]=y;
            mp[x][y]=num;
        }
        scanf("%d%d",&st.x,&st.y);
        bfs();
        for (int i=0;i<k;i++)
        {
            int xx=sx[i];
            int yy=sy[i];
            if (mp[xx][yy]!=0)
            {
                printf("1 %d\n",mp[xx][yy]);
            }
            else
            {
                printf("0 %d\n",sta[xx][yy]);
            }
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值