HDU 5336 XYZ and Drops(BFS)

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

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

点击打开链接

#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<queue>using namespace std;int r,c,n,pt;int mp[101][101];struct node{int xx;int yy;int tt;int ll;int dd;bool operator < (const node &px) const {return tt>px.tt;//最小值优先}};void BFS(int x,int y){priority_queue<node>q;while(!q.empty()){q.pop();}struct node t,f;for(int i=-1; i<=1; i++){for(int j=-1; j<=1; j++){if(i!=j && (abs(i-j)<=1)){t.xx = x;t.yy = y;t.tt = 0;t.dd = i;t.ll = j;if(t.xx<=r && t.yy<=c && t.xx>0 && t.yy>0){q.push(t);}}}}while(!q.empty()){t = q.top();q.pop();f.xx = t.xx + t.dd;f.yy = t.yy + t.ll;f.tt = t.tt + 1;if(f.xx<=r && f.yy<=c && f.xx>0 && f.yy>0){if(mp[f.xx][f.yy]>0 && f.tt<=pt){mp[f.xx][f.yy] += 1;}else{if(mp[f.xx][f.yy]<0 && f.tt == -mp[f.xx][f.yy]){}else if(f.tt<=pt){f.ll = t.ll;f.dd = t.dd;q.push(f);}}if(mp[f.xx][f.yy]>4){mp[f.xx][f.yy] = -1 * f.tt;for(int i=-1; i<=1; i++){for(int j=-1; j<=1; j++){if(i!=j && (abs(i-j)<=1)){struct node aa;aa.xx = f.xx;aa.yy = f.yy;aa.tt = f.tt;aa.ll = j;aa.dd = i;if(aa.xx<=r && aa.yy<=c && aa.xx>0 && aa.yy>0 && aa.tt<=pt){q.push(aa);}}}}}}}}int main(){while(scanf("%d%d%d%d",&r,&c,&n,&pt)!=EOF){int pl[110],pr[110];int x,y,z;memset(mp,0,sizeof(mp));for(int i=0; i<n; i++){scanf("%d%d%d",&x,&y,&z);pl[i] = x;pr[i] = y;mp[x][y] = z;}scanf("%d%d",&x,&y);BFS(x,y);for(int i=0; i<n; i++){if(mp[pl[i]][pr[i]]>0){printf("1 %d\n",mp[pl[i]][pr[i]]);}else if(mp[pl[i]][pr[i]]<0){printf("0 %d\n",-mp[pl[i]][pr[i]]);}}}return 0;}

版权声明:本文为博主原创文章,如有特殊需要请与博主联系 QQ : 793977586。

,愚公因此敢移山,矢志不渝是前行,握紧拳头勇登攀,

HDU 5336 XYZ and Drops(BFS)

相关文章:

你感兴趣的文章:

标签云: