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

hdu5336 多校联合第四场1010 模拟+bfs优先队列

时间:2015-07-31 21:57:52      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

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
/**
hdu5336 多校联合第四场1010   模拟+bfs
题目大意:很像一个游戏“十滴水”,在一个n*m的棋盘里有N个点有一些水滴,含水量为1~4,如果一滴水多于4则该水滴会向四个方向放射量为1
          的水,并且原位置水滴消逝,放射的水运动速度为1格/s,最开始在xy位置有一滴水崩裂,问T s时各初始状态的水滴的状态是什么
解题思路:因为水滴的迸射会产生连锁反应,因此我们用优先队列维护,bfs。
          值得一提的是如果2或以上的水同时到达一水滴,并该水滴迸射那么这些水滴同时消失。
*/
#include <string.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <queue>
using namespace std;
int n,m,N,T,num[1005][2],sta[1005][1005],time[1005][1005];
int dx[][2]= {1,0,0,1,-1,0,0,-1};
struct note
{
    int x,y,d,t;
    note() {}
    note(int _x,int _y,int _d,int _t)
    {
        x=_x,y=_y,d=_d,t=_t;
    }
    bool operator < (const note &other)const
    {
        return t>other.t;
    }
};

void bfs(int x,int y)
{
    memset(time,-1,sizeof(time));
    priority_queue<note> q;
    q.push(note(x,y,0,0));
    q.push(note(x,y,1,0));
    q.push(note(x,y,2,0));
    q.push(note(x,y,3,0));
    while(!q.empty())
    {
        note cnt=q.top();
        if(cnt.t>=T)return;
        q.pop();
        x=cnt.x+dx[cnt.d][0];
        y=cnt.y+dx[cnt.d][1];
        if(x<=0||x>n||y<=0||y>m||time[x][y]==cnt.t+1)continue;
        if(sta[x][y]!=0)
        {
            if(sta[x][y]==4)
            {
                sta[x][y]=0;
                time[x][y]=cnt.t+1;
                q.push(note(x,y,0,cnt.t+1));
                q.push(note(x,y,1,cnt.t+1));
                q.push(note(x,y,2,cnt.t+1));
                q.push(note(x,y,3,cnt.t+1));
            }
            else
            {
                sta[x][y]++;
            }
        }
        else
            q.push(note(x,y,cnt.d,cnt.t+1));
    }
}
int main()
{
    while(~scanf("%d%d%d%d",&n,&m,&N,&T))
    {
        memset(sta,0,sizeof(sta));
        for(int i=0; i<N; i++)
        {
            int x;
            scanf("%d%d%d",&num[i][0],&num[i][1],&x);
            sta[num[i][0]][num[i][1]]=x;
        }
        int x,y;
        scanf("%d%d",&x,&y);
        bfs(x,y);
        for(int i=0; i<N; i++)
        {
            if(time[num[i][0]][num[i][1]]==-1)
                printf("1 %d\n",sta[num[i][0]][num[i][1]]);
            else
                printf("0 %d\n",time[num[i][0]][num[i][1]]);
        }
    }
    return 0;
}


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

hdu5336 多校联合第四场1010 模拟+bfs优先队列

标签:

原文地址:http://blog.csdn.net/lvshubao1314/article/details/47175589

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