XYZ and Drops (hdu 5336 bfs)

XYZ and DropsTime Limit: 3000/1500 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 588Accepted Submission(s): 157

Problem Description

XYZ is playing an interesting game called "drops". It is played on agrid. 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 (), before the first second there is a waterdrop cracking at position (). XYZ wants to know each waterdrop’s status afterseconds, can you help him?

Input

The first line contains four integersstands for the numbers of waterdrops at the beginning.Each line of the followinglines contains three integers, meaning that the-th waterdrop is at position () and its size is. ()The next line contains two integers.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

lines. Each line contains two integers:If the-th waterdrop cracks inthe time when it cracked.If the-th waterdrop doesn’t crack inits size afterseconds.

Sample Input

4 4 5 102 1 42 3 32 4 43 1 24 3 44 4

Sample Output

0 50 30 21 30 1

Author

XJZX

Source

Recommend

wange2014|We have carefully selected several similar problems for you:53385337533553345333

题意: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 100005typedef __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];//该点大水滴的sizeint 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]){ //比赛时这个大括号内的没写,WAif (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);}}elsenum[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];elseq[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 62 2 42 4 24 4 42 5 44 2*/

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

你可以用爱得到全世界,你也可以用恨失去全世界

XYZ and Drops (hdu 5336 bfs)

相关文章:

你感兴趣的文章:

标签云: