码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5336 XYZ and Drops(模拟十滴水游戏 BFS啊)

时间:2015-08-02 11:51:36      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:hdu   多校2015   bfs   模拟   

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


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

题意:

在一个n * m 的矩阵中,一共有 num 个大水滴,求在经过了 T 秒后这 num 个大水滴的状态!

在 0 秒时 (x,y) 位置有个水滴开始爆炸,然后生成了四个小水滴分别向上下左右移动,每个大水滴的 Size > 4 就会爆炸,生成向四周移动的小水滴!

PS:

BFS,把每个小水滴压入优先队列里;

代码如下:

#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;
#define maxn 1017
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
struct node
{
    int x, y;
    int dir;
    int t;
    node() {}
    node(int _x, int _y, int _dir, int _t)
    {
        x = _x,y = _y, dir = _dir, t = _t;
    }
    bool operator < (const node &time)const
    {
        return t > time.t;
    }
};
struct NODE
{
    int x, y;
} a[maxn];
int n, m, T;
int Size[maxn][maxn];
int time[maxn][maxn];

int judge(int x, int y, int t)
{
    if(x<=0 || x>n || y<=0 || y>m || time[x][y]== t+1)
    {
        return 1;
    }
    return 0;
}
void init()
{
    memset(Size, 0, sizeof(Size));
    memset(time, -1,sizeof(time));
}
void BFS(int x, int y)
{
    priority_queue<node> q;
    for(int i = 0; i < 4; i++)
    {
        q.push(node(x, y, i, 0));
    }
    while(!q.empty())
    {
        node tt = q.top();
        if(tt.t >= T)
            return ;
        q.pop();
        int tx = tt.x + dx[tt.dir];
        int ty = tt.y + dy[tt.dir];
        if(judge(tx, ty, tt.t))
            continue;
        if(Size[tx][ty] != 0)
        {
            if(Size[tx][ty] == 4)
            {
                Size[tx][ty] = 0;
                time[tx][ty] = tt.t+1;
                for(int i = 0; i < 4; i++)
                {
                    q.push(node(tx, ty, i, tt.t+1));
                }
            }
            else
            {
                Size[tx][ty]++;
            }
        }
        else
        {
            q.push(node(tx, ty, tt.dir, tt.t+1));
        }
    }
}


int main()
{
    int num;
    while(~scanf("%d%d%d%d",&n,&m,&num,&T))
    {
        init();
        int _size;
        for(int i =  0; i < num; i++)
        {
            scanf("%d%d%d",&a[i].x,&a[i].y,&_size);
            Size[a[i].x][a[i].y] = _size;
        }
        int x, y;
        scanf("%d%d",&x,&y);
        BFS(x, y);
        for(int i = 0; i < num; i++)
        {
            if(time[a[i].x][a[i].y] != -1)//爆炸
            {
                printf("0 %d\n",time[a[i].x][a[i].y]);
            }
            else
            {
                printf("1 %d\n",Size[a[i].x][a[i].y]);
            }
        }
    }
    return 0;
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 5336 XYZ and Drops(模拟十滴水游戏 BFS啊)

标签:hdu   多校2015   bfs   模拟   

原文地址:http://blog.csdn.net/u012860063/article/details/47205397

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!