HDU 5336 XYZ and Drops(模拟十滴水游戏 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 (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

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

2015 Multi-University Training Contest 4

题意:

在一个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;
}

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

时间: 2024-09-30 07:08:50

HDU 5336 XYZ and Drops(模拟十滴水游戏 BFS啊)的相关文章

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): 1250    Accepted Submission(s): 407 Problem Description XYZ is playing an interesting game called "drops". It is played on a r∗

Hdu 5336 XYZ and Drops (bfs 模拟)

题目链接: Hdu 5336 XYZ and Drops 题目描述: 有一个n*m的格子矩阵,在一些小格子里面可能会有一些水珠,每个小水珠都有一个size.现在呢,游戏开始咯,在一个指定的空的小格子里面有一个将要向四周爆裂的水珠,在下一面分别向上,下,左,右四个方向发射一个小水滴,(小水滴与水珠同,小水滴没有size),当小水滴走向一个格子,这个格子如果是空或者有其他的小水滴同时走到这个格子的情况下,对小水滴的运动轨迹是不影响的.但是遇到水珠的话,小水滴就会被吸收,水珠每次吸收一个小水滴size

HDU 5336 XYZ and Drops (模拟+搜索,详解)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5336 题面: XYZ and Drops Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 725    Accepted Submission(s): 201 Problem Description XYZ is playing an in

hdu 5336 XYZ and Drops 【BFS模拟】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5336 题意:给你一个r*c的网格,有的网格为空,有的有水,再给出一个爆炸点,从这个点向四周爆出四个水滴,若碰到水则融为一体,若碰到其他水滴直接跑过去互不影响,每秒可跑一格,若水中水滴数量超过4则爆开,问T秒后网格的状态是怎样的. 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <li

hdu5336 XYZ and Drops (模拟+vector删除第i个元素)

题目链接: hdu5336 XYZ and Drops 模拟题一道,比较水,但是因为题意曲折 顺带vector的删除操作也是不太明白 总之逗了很长时间 删除第i个元素 v.erase(v.begin() + i); 删完后后面的元素都会往前移一个,所以下一个元素还是v[i] 也可以下面这样 it = v.erase(it); //erase()返回值是指向下一个元素的指针 //#define __LOCAL //#define __LLD #include <stdio.h> #include

HDU 5336 BFS+模拟

模拟十滴水游戏 r*c矩阵中,共有N个大水滴,求T秒后这N个水滴的状态 在0秒时在s_x,s_y位置有个水滴爆炸,生成向四周移动的小水滴,每个大水滴>4会爆炸,生成向四周移动的小水滴 把所有小水滴入队列,进行BFS即可,注意处理多个小水滴同时到达同一个大水滴的情况 #include "stdio.h" #include "string.h" #include "queue" using namespace std; const int di

HDU 5336(2015多校4)-XYZ and Drops(bfs)

题目地址:HDU 5336 题意:有一个r 行 c 列的格子,给出n个格子里有水滴的大小.再给出时间限制T,使得水滴从(sx,sy)位置开始爆破,当飞渐的水遇到格子里的静态水时就会聚在一起,当聚集的水滴大小>4时就会爆破.问在T时给定的n个位置格子里的水滴情况,如果没有爆破就输出:1 格子里水滴大小.否则输出:0 爆破的时间. #include <stdio.h> #include <math.h> #include <string.h> #include <

XYZ and Drops (hdu 5336 bfs)

XYZ and Drops Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 588    Accepted Submission(s): 157 Problem Description XYZ is playing an interesting game called "drops". It is played on a r?

HDU 1034 Candy Sharing Game 模拟题

一个分糖游戏,找了会规律,没找到,只能直接模拟玩了. 果然0ms过了,看来数据不大,只是考编码能力罢了. #include <stdio.h> #include <vector> #include <string.h> #include <algorithm> #include <iostream> #include <string> #include <limits.h> #include <stack> #