Hdu 5336 XYZ and Drops (bfs 模拟)
题目链接:
题目描述:
有一个n*m的格子矩阵,在一些小格子里面可能会有一些水珠,每个小水珠都有一个size。现在呢,游戏开始咯,在一个指定的空的小格子里面有一个将要向四周爆裂的水珠,在下一面分别向上,下,左,右四个方向发射一个小水滴,(小水滴与水珠同,小水滴没有size),当小水滴走向一个格子,这个格子如果是空或者有其他的小水滴同时走到这个格子的情况下,对小水滴的运动轨迹是不影响的。但是遇到水珠的话,小水滴就会被吸收,水珠每次吸收一个小水滴size会增加1。为了万物的平衡,水珠size大于4的话就会向四周爆裂成为小水滴。问T时间后每个水珠的状态。
解题思路:
就是bfs模拟一下小水滴运动的状态就ok了,比赛的时候一直卡题意。
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = ;
int dir[][] = {,, -,, ,, ,-};
struct node
{//坐标,运动方向,运动时间
int x, y, dir, t;
};
int maps[][maxn][maxn], point[maxn][];
int r, c, x, y, t; void bfs ()
{
queue <node> Q;
node p, q;
p.x = x;
p.y = y;
p.dir = ;
p.t = ;
Q.push (p);
while (!Q.empty())
{
p = Q.front ();
Q.pop ();
if (p.t >= t)
return ;
if (p.dir == )
{
for (int i=; i<; i++)
{
q.x = p.x + dir[i][];
q.y = p.y + dir[i][];
q.dir = i;
q.t = p.t + ;
if (>=q.x||q.x>r || >=q.y||q.y>c)
continue;
if (maps[][q.x][q.y] == q.t)
continue;
if ( !maps[][q.x][q.y] )
Q.push (q);
else
{
maps[][q.x][q.y] ++;
if (maps[][q.x][q.y] > )
{
maps[][q.x][q.y] = q.t;
maps[][q.x][q.y] = ;
q.dir = ;
Q.push (q);
}
}
}
}
else
{
q.x = p.x + dir[p.dir][];
q.y = p.y + dir[p.dir][];
q.dir = p.dir;
q.t = p.t + ;
if (>=q.x||q.x>r || >=q.y||q.y>c)
continue;
if (maps[][q.x][q.y] == q.t)
continue;
if ( !maps[][q.x][q.y] )
Q.push (q);
else
{
maps[][q.x][q.y] ++;
if (maps[][q.x][q.y] > )
{
maps[][q.x][q.y] = q.t;
maps[][q.x][q.y] = ;
q.dir = ;
Q.push (q);
}
}
} }
}
int main ()
{
int n, s;
while (scanf ("%d %d %d %d", &r, &c, &n, &t) != EOF)
{
memset (maps, , sizeof(maps));
for (int i=; i<n; i++)
{
scanf ("%d %d %d", &x, &y, &s);
point[i][] = x;
point[i][] = y;
maps[][x][y] = s;
}
scanf ("%d %d", &x, &y);
bfs ();
for (int i=; i<n; i++)
{
x = point[i][];
y = point[i][];
if (maps[][x][y] == )
printf ("0 %d\n", maps[][x][y]);
else
printf ("1 %d\n", maps[][x][y]);
}
}
return ;
}
Hdu 5336 XYZ and Drops (bfs 模拟)的更多相关文章
- HDU 5336——XYZ and Drops——————【广搜BFS】
XYZ and Drops Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 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_1495_非常可乐(bfs模拟)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1495 题意:不解释 题解:BFS模拟,不过要细心,把所有情况都列举出来,开一个数组记录状态,代码有点长 ...
- BFS+模拟 ZOJ 3865 Superbot
题目传送门 /* BFS+模拟:dp[i][j][p] 表示走到i,j,方向为p的步数为多少: BFS分4种情况入队,最后在终点4个方向寻找最小值:) */ #include <cstdio&g ...
- HDU 2717 Catch That Cow --- BFS
HDU 2717 题目大意:在x坐标上,农夫在n,牛在k.农夫每次可以移动到n-1, n+1, n*2的点.求最少到达k的步数. 思路:从起点开始,分别按x-1,x+1,2*x三个方向进行BFS,最先 ...
- hdu多校第十场 1009 (hdu6699) Block Breaker bfs/模拟
题意: 紧密排列的方块因为摩擦力一个一个稳定地挤在一起,但当一个方块的四个邻居中,上下两个至少空缺一个,左右两个至少空缺一个,则这个方块也将掉落. 每次锤掉一个方块,求多少个方块受牵连落下. 题解: ...
- POJ 3414 Pots【bfs模拟倒水问题】
链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...
随机推荐
- xml解析工具mashaller javaee自带解析类
1.怎样去掉Marshaller的格式化? : JAXBContext context = JAXBContext.newInstance(Entity.class); Marshaller mars ...
- Java时间戳转化为今天、昨天、明天(字符串格式)
原文:http://www.open-open.com/code/view/1435301895825 时间戳,相信大家一定都不陌生,服务器经常会传回来时间戳,需要我们对时间戳进行处理.各种麻烦不断, ...
- HNU 12834 Thread Tree
递归输出即可了 #include<bits/stdc++.h> using namespace std; struct tree{ int dot; string s; } ...
- OSWorkFlow流程配置文件具体解释
AbstractWorkflow>> osworkflow中有关工作流流转的全部核心代码都在AbstractWorkflow中.BasicWorkflow就是派生自它,只是这个BasicW ...
- libevent多线程使用事项
转 http://www.cnblogs.com/Seapeak/archive/2010/04/08/1707807.html 在linux平台上使用c开发网络程序的同志们一般情况下都对鼎鼎大名的l ...
- CF 234 C Weather(粗暴方法)
C. Color Stripe time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- LoadRunner系列之—-04 录制基于https协议的脚本
实际性能测试过程中,有些需录制脚本的页面或接口是基于https协议的,按原来方法录制脚本,录完了脚本是空的.为解决这个问题,第一步了解https协议的具体实现,这块网上资料很多,可参考页面下方参考资料 ...
- Spring AOP监控SQL运行
对数据库连接池Proxool比較熟悉的读者,都知道Proxool能够记录SQL运行内容和时间等信息日志. 我们能够将该日志记录专门的SQL日志文件.对于查找运行特别耗时的SQL起了不小的作用. 对于一 ...
- Hibernate 之 Mapping
转自: http://blog.csdn.net/jnqqls/article/details/8372732 从前面的介绍的Hibernate文章中我们已经对Hibernate有了一个初步的认识, ...
- qemu -net tap配置上网
1 该选项的用途 让qemu所在的宿主机器的tap网络接口和qemu的vlan n连接起来,从而进一步配置宿主机后,可以让qemu里面的操作系统可以通过vlan n里面的网卡上网. 2 真个系统的架构 ...