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?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

Recommend

wange2014   |   We have carefully selected several similar problems for you:  5338 5337 5335 5334 5333

题意:n个大水滴在r*c的平面上,(x,y)处有一水滴分裂,分成四个小水滴向四个方向前进,其他n个大水滴的初始大小为1~4,若大水滴被小水滴撞到大水滴大小增加一,当大水滴大小超过四时会分裂,同样向四个方向,这样连锁反应,问最后T时刻n个水滴的状态。

思路:bfs,比赛写的时候一个小bug没看出来,思路上的一点漏洞,遗憾。

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define DBG printf("Hi\n")
using namespace std;

#define mod 10000007

#define N 100005

typedef __int64 ll;

struct Node
{
    int x,y,t,d;
    bool operator<(const Node &a)const
    {
        return t>a.t;
    }
};

int r,c,n,T;
int num[111][111];//该点大水滴的size
int id[111][111];
int q[111][2];
bool have[111][111];
int out[111][111];
int dir[4][2]={1,0,0,1,-1,0,0,-1};

bool isok(int x,int y)
{
    if (x>=0&&x<r&&y>=0&&y<c) return true;
    return false;
}

int Search(int d,int x,int y,int &X,int &Y)
{
    int ans=0;
    while (isok(x,y)&&!have[x][y])
    {
        x=x+dir[d][0];
        y=y+dir[d][1];
        ans++;
    }
    if (!isok(x,y)) return -1;
    X=x;Y=y;
    return ans+1;
}

void bfs(int x,int y)
{
    Node st,now;
    priority_queue<Node>Q;
    while (!Q.empty()) Q.pop();
    st.x=x;st.y=y;
    st.t=0;
    Q.push(st);
    int cnt=0;
    while (!Q.empty())
    {
        if (cnt>=n+1) break;
        st=Q.top();
        Q.pop();
        if (!have[st.x][st.y])
        {   //比赛时这个大括号内的没写,WA
            if (out[st.x][st.y]==st.t) continue;
            int ss=Search(st.d,st.x,st.y,now.x,now.y);
            if (ss==-1) continue;
            now.d=st.d;
            now.t=st.t+ss-1;
            Q.push(now);
            continue;
        }
        if (num[st.x][st.y]+1>4)
        {
            cnt++;
            have[st.x][st.y]=false;
            out[st.x][st.y]=st.t;
            num[st.x][st.y]=0;
//            printf("***%d\n",st.t);
            for (int i=0;i<4;i++)
            {
                int dx=st.x+dir[i][0];
                int dy=st.y+dir[i][1];
                if (!isok(dx,dy)) continue;
                int ss=Search(i,dx,dy,now.x,now.y);
                if (ss==-1)  continue;
                now.t=st.t+ss;
                now.d=i;
//                printf("%d %d %d++\n",now.x,now.y,now.t);
                if (now.t>T) continue;
                Q.push(now);
            }
        }
        else
            num[st.x][st.y]++;
    }
}

int main()
{
    int i,j,x,y,z;
    while (~scanf("%d%d%d%d",&r,&c,&n,&T))
    {
        memset(num,0,sizeof(num));
        memset(id,-1,sizeof(id));
        memset(out,0,sizeof(out));
        memset(have,false,sizeof(have));
        for (i=0;i<n;i++)
        {
            scanf("%d%d%d",&x,&y,&z);
            x--;
            y--;
            num[x][y]=z;
            have[x][y]=true;
            id[x][y]=i;
        }
        scanf("%d%d",&x,&y);
        x--;y--;
        have[x][y]=true;
        num[x][y]=10;
        bfs(x,y);
        for (i=0;i<r;i++)
        {
            for (j=0;j<c;j++)
            {
                if (id[i][j]==-1) continue;
                if (have[i][j])
                    q[id[i][j]][0]=1,q[id[i][j]][1]=num[i][j];
                else
                    q[id[i][j]][0]=0,q[id[i][j]][1]=out[i][j];

            }
        }
        for (i=0;i<n;i++)
        {
            printf("%d %d\n",q[i][0],q[i][1]);
        }
    }
    return 0;
}
/*
4 5 4 6
2 2 4
2 4 2
4 4 4
2 5 4
4 2
*/

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

时间: 2024-07-29 17:39:49

XYZ and Drops (hdu 5336 bfs)的相关文章

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 BFS

点击打开链接 题意:有n个水池,每个水池目前的水滴数量给你了,一旦水池中的水滴数量大于4,这个水池就会爆,并且分成四个水滴向四个方向出发,水滴只有两种情况,一是走出地图二是碰到水池,现在给你一个爆炸点,这个点会向四个方向发射水滴,问你t秒后的所有点的状态,水滴一秒移动一个格 思路:就是用bfs去模拟一下每个水滴的状态,因为时间是10000,而水池共有100个,那么最坏的复杂度就是4000000,应该没问题,而且这题数据应该很水跑得还比较快,说一下做法,我们对于每一个时间点,来枚举一下当前队列里的

Hdu 5336 XYZ and Drops (bfs 模拟)

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

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

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 1175 bfs 转弯题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175 和之前的1728类似.就是判断转弯数,建立一个用于记录转弯数的数组.. 还有就是对于特殊情况要进行考虑,比如起点与终点相同的情况,对于本题来说是不可以消去的应该输出NO.还有就是起点或终点是零这也是不行的,因为0代表没有棋子... 还有在判断能不能走的时候要小心,对于判断条件一定要小心,不要图赶快写.. 错误的地方都写在注释中了.. 代码: // hdu 1175 bfs 转弯数 //1.起点

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

Saving Princess claire_(hdu 4308 bfs模板题)

http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2305    Accepted Submission(s): 822 Problem Description Princess claire_ wa