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∗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 afterT 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
 
题目大意:r行c列,n个水坑,时间T。xi,yi,vi表示水坑的位置和起始水量。x,y表示在这个位置在0时间发生迸射,水坑消失,在上下左右四个方向各自形成1个容量为1的小水滴,且如果不受水坑影响时,每单位时间向迸射方向前进1单位距离。其他的水坑会在水量超过4的时候发生迸射,水坑消失,形成小水滴。小水滴相遇不会出现反应,当小水滴出边界即消失,跟大水坑相遇时,融进大水坑,水坑水量增加1单位,小水滴消失。如果在同一时间有多个小水滴到达该水坑,那么如果超过4容量后,后面同时到达的小水滴就当做是融合在该水坑中,即消失。
 
#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
struct WaterDrops{ //水坑
int x,y;
WaterDrops(){}
WaterDrops(int xx,int yy){
x=xx,y=yy;
}
}waterdrops[maxn];
struct Drops{ //水滴
int x,y;
int dir,t;
Drops(){}
Drops(int xx,int yy,int d,int tt){
x=xx,y=yy,dir=d,t=tt;
}
}drops[maxn*5];
int crack[maxn][maxn],Map[maxn][maxn];//记录迸射、水坑容量
int f[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int r,c,T;
queue<Drops>Q;
bool inside(int x,int y){ //判断是否在边界中
if(x>=1&&x<=r&&y>=1&&y<=c){
return true;
}else{
return false;
}
}
void BFS(){
int xx, yy, tt, d,tx,ty;
Drops st;
while(!Q.empty()){
st=Q.front();
xx=st.x,yy=st.y,d=st.dir,tt=st.t;
Q.pop();
if(Map[xx][yy]){ //如果该位置还有水坑
Map[xx][yy]++;
if(Map[xx][yy]>4){
Map[xx][yy]=0; //容量置0
crack[xx][yy]=tt;//记录迸射时间
for(int i=0;i<4;i++){
tx=xx+f[i][0],ty=yy+f[i][1];
if(inside(tx,ty)){
if(tt+1<=T){
Q.push(Drops(tx,ty,i,tt+1));
}
}
}
}
}else if(crack[xx][yy]!=tt){//如果没有水坑或水坑迸射,且当前小水滴不是跟发生迸射的那个小水滴同时到达
tx=xx+f[d][0];
ty=yy+f[d][1];
if(inside(tx,ty)){
if(tt+1<=T){
Q.push(Drops(tx,ty,d,tt+1));
}
}
} }
}
void init(){
while(!Q.empty())
Q.pop();
memset(Map,0,sizeof(Map));
memset(crack,0,sizeof(crack));
}
int main(){
int n,xx,yy,val,tx,ty;
while(scanf("%d%d%d%d",&r,&c,&n,&T)!=EOF){
init();
for(int i=1;i<=n;i++){
scanf("%d%d%d",&xx,&yy,&val);
waterdrops[i].x=xx,waterdrops[i].y=yy;
Map[xx][yy]=val;
}
scanf("%d%d",&xx,&yy);
crack[xx][yy]=1;
for(int i=0;i<4;i++){
tx=xx+f[i][0];
ty=yy+f[i][1];
if(inside(tx,ty)){
Q.push(Drops(tx,ty,i,1));
}
}
BFS(); for(int i=1;i<=n;i++){
tx=waterdrops[i].x,ty=waterdrops[i].y;
if(Map[tx][ty]==0){
printf("0 %d\n",crack[tx][ty]);
}else{
printf("1 %d\n",Map[tx][ty]);
}
}
}
return 0;
}

  

HDU 5336——XYZ and Drops——————【广搜BFS】的更多相关文章

  1. Hdu 5336 XYZ and Drops (bfs 模拟)

    题目链接: Hdu 5336 XYZ and Drops 题目描述: 有一个n*m的格子矩阵,在一些小格子里面可能会有一些水珠,每个小水珠都有一个size.现在呢,游戏开始咯,在一个指定的空的小格子里 ...

  2. hdu 2717 Catch That Cow(广搜bfs)

    题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...

  3. 2015 Multi-University Training Contest 4 hdu 5336 XYZ and Drops

    XYZ and Drops Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  4. HDU 5336 XYZ and Drops

    Problem Description XYZ is playing an interesting game called "drops". It is played on a r ...

  5. HDU 5336 XYZ and Drops 2015 Multi-University Training Contest 4 1010

    这题的题意是给你一幅图,图里面有水滴.每一个水滴都有质量,然后再给你一个起点,他会在一開始的时候向四周发射4个小水滴,假设小水滴撞上水滴,那么他们会融合,假设质量大于4了,那么就会爆炸,向四周射出质量 ...

  6. hdu 1253:胜利大逃亡(基础广搜BFS)

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  7. poj3126 Prime Path 广搜bfs

    题目: The ministers of the cabinet were quite upset by the message from the Chief of Security stating ...

  8. hdu 1253 胜利大逃亡 (广搜)

    题目链接 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个ABC的立方体,可以被表示成A个 ...

  9. 算法学习笔记(六) 二叉树和图遍历—深搜 DFS 与广搜 BFS

    图的深搜与广搜 复习下二叉树.图的深搜与广搜. 从图的遍历说起.图的遍历方法有两种:深度优先遍历(Depth First Search), 广度优先遍历(Breadth First Search),其 ...

随机推荐

  1. 免费证书申请——Let's Encrypt的申请与应用(IIS,Tomcat)

    环境 Windows Server 2008 R2 Tomcat 8.5.31 JDK8 利用IIS+letsencrypt-win-simple.V1.9.1申请免费SSL证书 新建一个IIS空网站 ...

  2. Delphi 关键字详解

    Delphi 关键字详解[整理于 "橙子" 的帖子] absolute //它使得你能够创建一个新变量, 并且该变量的起始地址与另一个变量相同. var   Str: ];   S ...

  3. WC2019 冬眠记

    Day1 做高铁来广州 晚上开幕式,亮点在CCF的日常讲话.dzd有事换wh讲. 我们WC比赛的人数是最多的,性价比是最高的 然后掌声雷动 相信大家鼓掌是同意我的话 再次掌声雷动(雾 Day2-Day ...

  4. E - 稳定排序(结构体)

    大家都知道,快速排序是不稳定的排序方法. 如果对于数组中出现的任意a[i],a[j](i<j),其中a[i]==a[j],在进行排序以后a[i]一定出现在a[j]之前,则认为该排序是稳定的. 某 ...

  5. 洛谷P5206 [WC2019] 数树(生成函数+容斥+矩阵树)

    题面 传送门 前置芝士 矩阵树,基本容斥原理,生成函数,多项式\(\exp\) 题解 我也想哭了--orz rqy,orz shadowice 我们设\(T1,T2\)为两棵树,并定义一个权值函数\( ...

  6. (Python OpenGL)【3】着色器 PyOpenGL

    (Python OpenGL)现在开始我们使用着色器来进行渲染.着色器是目前做3D图形最流行的方式. OpenGL的渲染管线流程: 数据传输到OpenGL—>顶点处理器—>细分着色—> ...

  7. 二维树状数组总结&&【洛谷P4514】 上帝造题的七分钟

    P4514 上帝造题的七分钟 题目描述 "第一分钟,X说,要有矩阵,于是便有了一个里面写满了00的n×mn×m矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为(a,b)(a,b),右下 ...

  8. NSFileManager在初始化文件的时候一不留神就进入陷阱

    今天调试一个程序,内容是在手机一个本地路径生成一个缓存文件,在生成本地路径的时候犯了一个错误,本着求原因的精神调试了2个小时,终于找到原因了 刚开始断点调试的时候,执行到第13行,这里死活不给写入数据 ...

  9. Qt 学习之路 2(23):自定义事件

    Qt 学习之路 2(23):自定义事件  豆子  2012年10月23日  Qt 学习之路 2  21条评论 尽管 Qt 已经提供了很多事件,但对于更加千变万化的需求来说,有限的事件都是不够的.例如, ...

  10. Qt 学习之路 2(20):event()

    Qt 学习之路 2(20):event() 豆子 2012年10月10日 Qt 学习之路 2 43条评论 前面的章节中我们曾经提到event()函数.事件对象创建完毕后,Qt 将这个事件对象传递给QO ...