题目链接:

  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 ;
}

最新文章

  1. HTML5新增标签与属性
  2. Visual Studio(VS2012) Project&amp;(Solution) 虚拟文件夹 &amp; 物理文件夹
  3. C++中使用初始化列表比在构造函数中对成员变量赋值更高效
  4. noip2010-t2
  5. Centos 6.5(64bit)上安装Vertica single node
  6. 安装xampp后,出现“Apache 2 Test Page powered by CentOS“
  7. zabbix邮件报警脚本
  8. 郁闷~win7无法进行局域网访问解决
  9. 第三种:NSOperationQueue
  10. STM32 Keil查看程序占用ROM和RAM
  11. Qt编译
  12. EXT 结构解析
  13. SpringBoot定时任务
  14. ci 配置ckeditor + ckfinder 无图片上传按钮
  15. Android应用系列:完美运行GIF格式的ImageView(附源码)
  16. www.jqhtml.com 前端框架特效
  17. zzw原创_expdp及impdp中的exclude及include参数的那点事
  18. jquery.timers使用说明
  19. 基于ELK和Python搭建简单的监控告警系统
  20. ACM数论之旅10---大组合数-卢卡斯定理(在下卢卡斯,你是我的Master吗?(。-`ω&#180;-) )

热门文章

  1. 学习MarkDown--初体验
  2. js:简单的拖动效果
  3. Java中正则Matcher类的matches()、lookAt()和find()的差别
  4. VC++ 2010编译错误 fatal error C1189 error This file requires _WIN32_WINNT to be #defined at least
  5. Malformed or corrupted AST file: &amp;#39;Unable to load module &amp;quot;...
  6. Native进程之Trace原理(转)——可直接输出某进程的栈帧——debuggerd
  7. QtQuick桌面应用开发指导 1)关于教程 2)原型和设计 3)实现UI和功能_A
  8. Android 4.4.2 动态加入JNI库方法记录 (二 app应用层)
  9. asp.net mvc + javascript生成下载文件
  10. hibernate could not resolve property