题目链接:

  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. Android 开源框架ViewPageIndicator 和 ViewPager 仿网易新闻clientTab标签

    之前用JakeWharton的开源框架ActionBarSherlock和ViewPager实现了对网易新闻clientTab标签的功能,ActionBarSherlock是在3.0下面的机器支持Ac ...

  2. [Javascript] Use JavaScript's for-in Loop on Objects with Prototypes

    Loops can behave differently when objects have chained prototype objects. Let's see the difference w ...

  3. hdu1042 (模拟n!)

    题目大意: 求 n.(可能会超过整数范围,这里用数组模拟n!的值) pid=1042">http://acm.hdu.edu.cn/showproblem.php?pid=1042 A ...

  4. Office WORD EXCEL批量查找和替换技巧实例

    1 删除多余的空行 如果是在WORD中,则查找^p^p替换为^p.   如果是在EXCEL里,则为全部选中,然后点击编辑,定位,定位条件,空值. 将全部选中空白的行,如图所示 再次点击编辑,删除,删除 ...

  5. SQL 主机

    SQL 主机 SQL 主机 如果您想要您的网站存储数据在数据库并从数据库显示数据,您的 Web 服务器必须能使用 SQL 语言访问数据库系统. 如果您的 Web 服务器托管在互联网服务提供商(ISP, ...

  6. 【LeetCode】Swap Nodes in Pairs 链表指针的应用

    题目:swap nodes in pairs <span style="font-size:18px;">/** * LeetCode Swap Nodes in Pa ...

  7. 网络知识: 物理层PHY 和 网络层MAC

    PHY模块简介 物理层位于OSI最底层,物理层协议定义电气信号.线的状态.时钟要求.数据编码和数据传输用的连接器. 物理层的器件称为PHY. 上图里的灰色方框图里的就是PHY芯片内部模块图. MAC器 ...

  8. Python安装Mysql驱动出错解决(最新出炉)

    Python中最连接Mysql常用的驱动是 mysql-python :mysql的C语言的驱动 mysql-connector:msql官方的驱动 pymysql:python语言的驱动 我这里安装 ...

  9. python爬虫爬取内容中,-xa0,-u3000的含义

    python爬虫爬取内容中,-xa0,-u3000的含义 - CSDN博客 https://blog.csdn.net/aiwuzhi12/article/details/54866310

  10. Delphi指向函数指针的指针

    type TFunc=procedure; procedure MyFunc; begin ShowMessage('Run my func'); end; procedure TForm1.Butt ...