题目链接:

  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. [React] PureComponent in React

    In this lesson, you will learn how to use PureComponent in React to reduce the number of times your ...

  2. 【笨木头Lua专栏】基础补充07:协同程序初探

    哎.周五晚上我都还这么努力看书.真是好孩子.(小若:不想吐槽了) 事实上我都准备rs=1&u=http%3A%2F%2Fwww%2Ebenmutou%2Ecom%2Farchives%2F17 ...

  3. VC++如何折叠代码

    工具-选项,然后在文本编辑器,C/C++中的格式设置,把大纲语句块设置为True   这样之后,还是不能像C#一样使用region折叠代码,但是可以方法和if语句都会自动显示可以折叠.   使用#pr ...

  4. Web开发从零单排之一:在新浪云平台SAE上开发一个html5电子喜帖

    需求描述: 本人大婚将至,女朋友说“现在都流行在微信上发电子请帖了,你不是技(cheng)术(xu)宅(yuan)嘛,不会连这个都搞不定吧” 本人嘴上说这等小事何足挂齿,但心里还是七上八下的,虽然自认 ...

  5. 暴力破解zip文件

    #coding=utf-8 """ 用户输入-z参数指定要破解的zip文件,输入-d参数输入字典文件,即可暴力破解加密的zip文件 """ ...

  6. 2016/05/16 UEditor 文本编辑器 使用教程与使用方法

    第一:百度UEditor编辑器的官方下载地址 ueditor 官方地址:http://ueditor.baidu.com/website/index.html 开发文档地址:http://uedito ...

  7. Codefoces 791D. Bear and Tree Jumps 树形DP

    D. Bear and Tree Jumps   A tree is an undirected connected graph without cycles. The distance betwee ...

  8. make的特殊之处

    1 规则的先后顺序问题 规则的先后顺序只会影响默认的目标,没有其它的影响. 2 make对具有相同目标的规则的处理方式 2.1 如果是单冒号 只能有一个规则是有命令的,然后对它们进行合并,即依赖合并. ...

  9. 磁盘扩容 磁盘阵列(Redundant Arrays of Independent Disks,RAID)

    磁盘阵列(Redundant Arrays of Independent Disks,RAID) 云 500G  不够用 扩容 方案1  重建分区,由500G到1T,按历史增速,1年后再扩到1.5T, ...

  10. plink 与 ssh 远程登录问题

    plink 是一种 putty-tools,ubuntu 环境下,如果没有安装 plink,可通过如下方法进行安装: $ echo y | sudo apt-get install plink 1. ...