HDU 3533 Escape (BFS + 预处理)
Escape
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 541 Accepted Submission(s): 141
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std; const int SIZE = ;
const int UPDATE[][] = {{,},{,},{,}};
int N,M,K,E;
bool FIRE[SIZE][SIZE][];
bool VIS[SIZE][SIZE][];
bool CASTLE[SIZE][SIZE];
struct Node
{
int x,y,t,e;
bool check(void)
{
if(x < || x > N || y < || y > M || t > E || VIS[x][y][t] || CASTLE[x][y] ||
FIRE[x][y][t] || !e || N - x + M - y > e)
return false;
return true;
}
};
struct Cas
{
char ch;
int t,v,x,y;
}; void deal(char ch,int t,int v,int x,int y);
void bfs(void);
int main(void)
{
Cas temp[];
while(scanf("%d%d%d%d",&N,&M,&K,&E) != EOF)
{
fill(&FIRE[][][],&FIRE[SIZE - ][SIZE - ][],false);
fill(&VIS[][][],&VIS[SIZE - ][SIZE - ][],false);
fill(&CASTLE[][],&CASTLE[SIZE - ][SIZE - ],false); for(int i = ;i < K;i ++)
{
scanf(" %c%d%d%d%d",&temp[i].ch,&temp[i].t,&temp[i].v,&temp[i].x,&temp[i].y);
CASTLE[temp[i].x][temp[i].y] = true;
}
if(CASTLE[N][M])
{
puts("Bad luck!");
continue;
}
for(int i = ;i < K;i ++)
deal(temp[i].ch,temp[i].t,temp[i].v,temp[i].x,temp[i].y);
bfs();
} return ;
} void deal(char ch,int t,int v,int x,int y)
{
if(ch == 'W')
{
int stop = ;
for(int j = y - ;j >= ;j --)
if(CASTLE[x][j])
{
stop = j;
break;
}
for(int j = y - v,ini = ;j >= stop;j -= v,ini ++)
for(int k = ini;k <= E;k += t)
FIRE[x][j][k] = true; }
else if(ch == 'E')
{
int stop = M;
for(int j = y + ;j <= M;j ++)
if(CASTLE[x][j])
{
stop = j;
break;
} for(int j = y + v,ini = ;j <= stop;j += v,ini ++)
for(int k = ini;k <= E;k += t)
FIRE[x][j][k] = true;
}
else if(ch == 'N')
{
int stop = ;
for(int j = x - ;j >= ;j --)
if(CASTLE[j][y])
{
stop = j;
break;
}
for(int j = x - v,ini = ;j >= stop;j -= v,ini ++)
for(int k = ini;k <= E;k += t)
FIRE[j][y][k] = true;
}
else if(ch == 'S')
{
int stop = N;
for(int j = x + ;j <= N;j ++)
if(CASTLE[j][y])
{
stop = j;
break;
}
for(int j = x + v,ini = ;j <= stop;j += v,ini ++)
for(int k = ini;k <= E;k += t)
FIRE[j][y][k] = true;
}
} void bfs(void)
{
Node first;
first.x = first.y = first.t = ;
first.e = E;
queue<Node> que;
que.push(first);
VIS[][][] = true; while(!que.empty())
{
Node cur = que.front();
que.pop(); for(int i = ;i < ;i ++)
{
Node next = cur;
next.x += UPDATE[i][];
next.y += UPDATE[i][];
next.t ++;
next.e --;
if(!next.check())
continue;
if(next.x == N && next.y == M)
{
printf("%d\n",next.t);
return ;
}
VIS[next.x][next.y][next.t] = true;
que.push(next);
}
}
puts("Bad luck!");
}
HDU 3533 Escape (BFS + 预处理)的更多相关文章
- 【搜索】 HDU 3533 Escape BFS 预处理
要从0,0 点 跑到m,n点 路上会有k个堡垒发射子弹.有子弹的地方不能走,子弹打到别的堡垒就会消失,或者一直飞出边界(人不能经过堡垒 能够上下左右或者站着不动 每步都须要消耗能量 一共同拥有en ...
- HDU 3533 Escape bfs 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=3533 一道普通的bfs,但是由于代码实现出了bug还是拖了很久甚至对拍了 需要注意的是: 1.人不能经过炮台 2 ...
- HDU 3533 Escape(bfs)
Escape Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 3533 Escape BFS搜索
题意:懒得说了 分析:开个no[100][100][1000]的bool类型的数组就行了,没啥可说的 #include <iostream> #include <cstdio> ...
- HDU 3533 Escape(大逃亡)
HDU 3533 Escape(大逃亡) /K (Java/Others) Problem Description - 题目描述 The students of the HEU are maneu ...
- HDU 3533 Escape(BFS+预处理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 题目大意:给你一张n* m的地图,人在起点在(0,0)要到达终点(n,m)有k(k<=10 ...
- POJ-1077 HDU 1043 HDU 3567 Eight (BFS预处理+康拓展开)
思路: 这三个题是一个比一个令人纠结呀. POJ-1077 爆搜可以过,94ms,注意不能用map就是了. #include<iostream> #include<stack> ...
- HDU3533 Escape —— BFS / A*算法 + 预处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others) ...
- HDU - 1430 魔板 (bfs预处理 + 康托)
对于该题可以直接预处理初始状态[0, 1, 2, 3, 4, 5, 6, 7]所有可以到达的状态,保存到达的路径,直接打印答案即可. 关于此处的状态转换:假设有初始状态为2,3,4,5,0,6,7,1 ...
随机推荐
- LNMP最新源码安装脚本(定期更新)
Linux+Nginx+MySQL+PHP+Pureftpd+User manager for PureFTPd,脚本中用到的软件包大多最新版本,修复了User manager for PureFTP ...
- 软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] [附加题]
软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] [附加题] 首先,在分组之前,我和室友薛亚杰已经详细阅读了往届学长的博客,认为电梯调度 ...
- html5+css3中的background: -moz-linear-gradient 用法
在CSS中background: -moz-linear-gradient 让网站背景渐变的属性,目前火狐3.6以上版本和google浏览器支持这个属性. background: -moz-linea ...
- How to include JavaScript file in JSF
In JSF 2.0, you can use <h:outputScript /> tag to render a HTML "script" element, an ...
- 集合引入(ArrayList、LinkedList)
1.引入 代替数组固定大小操作不变 2.ArrayList 常用的操作(add,remove) 3.LinkedList 能实现一些特殊的操作(pop)
- 提高Scrum站会效率的一个小工具
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:提高Scrum站会效率的一个小工具.
- 445port入侵具体解释
445port入侵具体解释 关于"445port入侵"的内容445port入侵具体解释本站搜索很多其它关于"445port入侵"的内容 445port入侵, ...
- 【转】单例模式(python/c++)
1. 什么是单例模式(Singleton pattern)? 单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例类的特殊类.通过单例模式可以保证系统中一个类只有一个实例而且该实例易 ...
- 学习JSONP
最近自己研究 跨域调用js,然后 发现 有jsonp 这种技术,在Jquery中可以使用,于是 研究下原理 发现: 其实 就是 利用<script>的跨域访问的能力. 调用 服务端 返回的 ...
- c# windowsForm打印
在windows应用程序中文档的打印是一项非常重要的功能,在以前一直是一个非常复杂的工作,Microsoft .net Framework的打 印功能都以组件的方式提供,为程序员提供了很大的方便,但是 ...