0
点赞
收藏
分享

微信扫一扫

HDU 5336 XYZ and Drops(BFS)

七千22 2023-04-21 阅读 19


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


r∗c 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?

1≤r≤100,  1≤c≤100,  1≤n≤100,  1≤T≤10000


 



Input


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


 



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


 



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




点击打开链接




#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;
}





举报

相关推荐

0 条评论