hdu5336 多校聯合第四場1010 模擬+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
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).
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.
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
/**
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;
}
相關文章
- hdu5040 優先佇列+bfs佇列
- 【BFS+優先佇列】HDU 3442 Three Kingdoms佇列
- acmdream1191 bfs+優先佇列ACM佇列
- UVALive 6665 Dragon’s Cruller (BFS + 優先佇列+hash)Go佇列
- CSP之公共鑰匙盒(模擬、排序、優先佇列)排序佇列
- 「模擬賽」多校 A 層聯訓 16
- HDU 1026(優先佇列+BFS+前驅記錄)佇列
- PHP優先佇列PHP佇列
- 堆--優先佇列佇列
- 優先佇列 (轉)佇列
- 【資料結構】堆排序和模擬實現優先順序佇列!!資料結構排序佇列
- 合併果子(優先佇列 +或者+哈夫曼)佇列
- 淺談優先佇列佇列
- STL 優先佇列 用法佇列
- 堆與優先佇列佇列
- 堆和優先佇列佇列
- hdu 4546 優先佇列 數列組合和第m小佇列
- 聯賽模擬測試18 A. 施工 單調佇列(棧)優化DP佇列優化
- 「模擬賽」A 層多校聯訓 4(賣品:CTH)
- 優先佇列和堆排序佇列排序
- 堆排序與優先佇列排序佇列
- Java優先佇列(PriorityQueue)示例Java佇列
- 【堆】【優先佇列】[NOIP2004]合併果子佇列
- 陣列模擬佇列 以及佇列的複用(環形佇列)陣列佇列
- 01揹包優先佇列優化佇列優化
- NOIP模擬96(多校29)
- NOIP模擬92(多校25)
- NOIP模擬88(多校21)
- NOIP模擬83(多校16)
- NOIP模擬86(多校19)
- RMQ——支援合併和優先順序的訊息佇列MQ佇列
- 1284 海港 普及組 NOIP2016 佇列基礎 簡單列舉 簡單模擬 優先佇列(priority_queue)佇列
- 棧,佇列,優先順序佇列簡單介面使用佇列
- Redis實現任務佇列、優先順序佇列Redis佇列
- NO GAME NO LIFE(優先佇列/最小堆)GAM佇列
- 優先佇列的比較器佇列
- 封裝優先順序佇列封裝佇列
- 二叉堆優先佇列佇列