HDU 5336——XYZ and Drops——————【广搜BFS】
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
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
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).
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.
#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】的更多相关文章
- Hdu 5336 XYZ and Drops (bfs 模拟)
题目链接: Hdu 5336 XYZ and Drops 题目描述: 有一个n*m的格子矩阵,在一些小格子里面可能会有一些水珠,每个小水珠都有一个size.现在呢,游戏开始咯,在一个指定的空的小格子里 ...
- hdu 2717 Catch That Cow(广搜bfs)
题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...
- 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 ...
- HDU 5336 XYZ and Drops
Problem Description XYZ is playing an interesting game called "drops". It is played on a r ...
- HDU 5336 XYZ and Drops 2015 Multi-University Training Contest 4 1010
这题的题意是给你一幅图,图里面有水滴.每一个水滴都有质量,然后再给你一个起点,他会在一開始的时候向四周发射4个小水滴,假设小水滴撞上水滴,那么他们会融合,假设质量大于4了,那么就会爆炸,向四周射出质量 ...
- hdu 1253:胜利大逃亡(基础广搜BFS)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- poj3126 Prime Path 广搜bfs
题目: The ministers of the cabinet were quite upset by the message from the Chief of Security stating ...
- hdu 1253 胜利大逃亡 (广搜)
题目链接 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个ABC的立方体,可以被表示成A个 ...
- 算法学习笔记(六) 二叉树和图遍历—深搜 DFS 与广搜 BFS
图的深搜与广搜 复习下二叉树.图的深搜与广搜. 从图的遍历说起.图的遍历方法有两种:深度优先遍历(Depth First Search), 广度优先遍历(Breadth First Search),其 ...
随机推荐
- 在GridView控件FooterTemplate内添加记录 Ver3
重构此篇<在GridView控件FooterTemplate内添加记录 Ver2> http://www.cnblogs.com/insus/p/3270644.html 这有些缺陷,怎样 ...
- C# 服务器端控件
服务器端控件和客户端控件的比较? 区别:服务器端控件都会有个runat="Server"属性,这样才能够在后台对其进行设置修改,也就是在cs代码里面能对其修改设置.你做下测试 你放 ...
- Linux根目录结构
1: bin目录 此目录存放所有二进制命令(用户) 2: boot目录 Linux内核及引导系统程序所需的目录 3: dev目录 所有设备文件的目录(如声卡.磁盘.光驱) 4: etc目录 二 ...
- Java——事务
一.事务(Transaction) 1. 在开发中我们的一个业务往往需要同时操作多个表,这些操作往往是不可分割,业务中的对数据库的多次操作,要么同时成功,要么全都失败. 2.注意:我们在同一个事务中使 ...
- web flash推流h264视频取消cbr
flash as3.0 推视频H264关于视频质量 初次设置代码如下: h264Setting.setProfileLevel(H264Profile.BASELINE, H264Level.LEVE ...
- node mysql问题:Client does not support authentication protocol requested by server; consider upgrading MySQL client!
node后台 mysql处理模块(版本:2.16.0) 执行connect方法时报错: Client does not support authentication protocol requeste ...
- java 反射 处理 空值
package org.zkdg.utils.spring.annotations.impl; import java.lang.annotation.Annotation; import java. ...
- spring 配置properties 编码
<!-- properties 配置文件 --> <bean id="propertyConfigurer" class="org.springfram ...
- Django 的 model form 组件
Django 的 model form 组件 Model Form 组件的由来 之前介绍过 Django 的 Form 组件(Django的Form表单)使用方法,Form 组件能够帮我们做三件事: ...
- python 字符串的特性
#######str字符串#####str字符判断大小写 url1 = 'http://www.cctv.com' url2 = 'file:///mnt' print url1.startsw ...