题目链接:

  Hdu 5336 XYZ and Drops

题目描述:

  有一个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 模拟)的更多相关文章

  1. HDU 5336——XYZ and Drops——————【广搜BFS】

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

  2. 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 ...

  3. HDU 5336 XYZ and Drops

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

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

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

  5. hdu_1495_非常可乐(bfs模拟)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1495 题意:不解释 题解:BFS模拟,不过要细心,把所有情况都列举出来,开一个数组记录状态,代码有点长 ...

  6. BFS+模拟 ZOJ 3865 Superbot

    题目传送门 /* BFS+模拟:dp[i][j][p] 表示走到i,j,方向为p的步数为多少: BFS分4种情况入队,最后在终点4个方向寻找最小值:) */ #include <cstdio&g ...

  7. 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,最先 ...

  8. hdu多校第十场 1009 (hdu6699) Block Breaker bfs/模拟

    题意: 紧密排列的方块因为摩擦力一个一个稳定地挤在一起,但当一个方块的四个邻居中,上下两个至少空缺一个,左右两个至少空缺一个,则这个方块也将掉落. 每次锤掉一个方块,求多少个方块受牵连落下. 题解: ...

  9. POJ 3414 Pots【bfs模拟倒水问题】

    链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...

随机推荐

  1. c++之NVI手法

    non-virtual interface(NVI)手法:令用户通过public non-virtual成员函数间接调用private virtual函数,将这个non-virtual函数称为virt ...

  2. Spring4.0MVC学习资料,注解自己主动扫描bean,自己主动注入bean(二)

    Spring4.0的新特性我们在上一章已经介绍过了. 包含它对jdk8的支持,Groovy Bean Definition DSL的支持.核心容器功能的改进,Web开发改进.測试框架改进等等.这张我们 ...

  3. Binder系列8—如何使用Binder(转)

    一.Native层Binder 源码结构: ClientDemo.cpp: 客户端程序 ServerDemo.cpp:服务端程序 IMyService.h:自定义的MyService服务的头文件 IM ...

  4. android-调用系统的ContentPrivder获取单张图片实现剪切做头像及源代码下载

    首先讲述这个小项目的特色: 1.调用系统的相冊应用获取单张图片 2.对单张图片进行剪切方便做成指定大小的头像图片 3.对获取图片的结果进行解析,使用三种方式进行. 首先看看效果图: 打开app,进入注 ...

  5. mina客户端与服务端通信的易错点

    使用mina进行项目开发时,如果客户端与服务端不在同一个项目下,需要关注一下两点: 第一.服务端与客户端的编码解码器一致 第二.过程中所用到的实体类的包名需要一致

  6. jquery获取input值的各种情况

    jQuery获取多种input值的方法 获取input的checked值是否为true: 第一种: if($("input[name=item][value='val']").at ...

  7. [Sciter] Script与Native交互

    原帖地址:http://www.cnblogs.com/yinxufeng/p/5653920.html Script与Native交互基础简化方式Script调用NativeNative调用Scri ...

  8. SpringMVC_基本配置 --跟海涛学SpringMVC(和自己在项目中的实际使用的对比)

    ☆依赖jar包: 1.Spring框架jar 包: 为了简单,将spring-framework-3.1.1.RELEASE-with-docs.zip/dist/下的所有jar包拷贝到项目的WEB- ...

  9. 60年代进程 80年代线程 IPC How the Java Virtual Machine (JVM) Works

    小结: 1. To facilitate communication between processes, most operating systems support Inter Process C ...

  10. SAP更改日志记录表

    CDHDR  更改日志表头 CDPOS  更改日志行项目 SAP中修改频率较低的定制表(T001等)一般都会有修改记录存在,查看一个表有没有修改记录可以在SE11中查看他的技术设置,如果其中的LOG ...