HDU 3533 Escape(bfs)
Escape
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 598 Accepted Submission(s): 153Problem DescriptionThe students of the HEU are maneuvering for their military training.
The red army and the blue army are at war today. The blue army finds that Little A is the spy of the red army, so Little A has to escape from the headquarters of the blue army to that of the red army. The battle field is a rectangle of size m*n, and the headquarters of the blue army and the red army are placed at (0, 0) and (m, n), respectively, which means that Little A will go from (0, 0) to (m, n). The picture below denotes the shape of the battle field and the notation of directions that we will use later.
The blue army is eager to revenge, so it tries its best to kill Little A during his escape. The blue army places many castles, which will shoot to a fixed direction periodically. It costs Little A one unit of energy per second, whether he moves or not. If he uses up all his energy or gets shot at sometime, then he fails. Little A can move north, south, east or west, one unit per second. Note he may stay at times in order not to be shot.
To simplify the problem, let’s assume that Little A cannot stop in the middle of a second. He will neither get shot nor block the bullet during his move, which means that a bullet can only kill Little A at positions with integer coordinates. Consider the example below. The bullet moves from (0, 3) to (0, 0) at the speed of 3 units per second, and Little A moves from (0, 0) to (0, 1) at the speed of 1 unit per second. Then Little A is not killed. But if the bullet moves 2 units per second in the above example, Little A will be killed at (0, 1).
Now, please tell Little A whether he can escape.InputFor every test case, the first line has four integers, m, n, k and d (2<=m, n<=100, 0<=k<=100, m+ n<=d<=1000). m and n are the size of the battle ground, k is the number of castles and d is the units of energy Little A initially has. The next k lines describe the castles each. Each line contains a character c and four integers, t, v, x and y. Here c is ‘N’, ‘S’, ‘E’ or ‘W’ giving the direction to which the castle shoots, t is the period, v is the velocity of the bullets shot (i.e. units passed per second), and (x, y) is the location of the castle. Here we suppose that if a castle is shot by other castles, it will block others’ shots but will NOT be destroyed. And two bullets will pass each other without affecting their directions and velocities.
All castles begin to shoot when Little A starts to escape.
Proceed to the end of file.OutputIf Little A can escape, print the minimum time required in seconds on a single line. Otherwise print “Bad luck!” without quotes.Sample Input4 4 3 10
N 1 1 1 1
W 1 1 3 2
W 2 1 2 4
4 4 3 10
N 1 1 1 1
W 1 1 3 2
W 1 1 2 4Sample Output9
Bad luck!Source
/*************************************************************************
> File Name: hdu_3533.cpp
> Author: Howe_Young
> Mail: 1013410795@qq.com
> Created Time: 2015年04月28日 星期二 19时14分24秒
************************************************************************/ #include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue> using namespace std;
const int maxn = ;
const int Next[][] = {, , , , , -, -, , , };//可以四个方向,也可以呆在原地不动
int n, m, k, d;
struct castle{//碉堡
char dir;//炮塔方向
int t, v;//t是周期,v是速度
};
struct Node{
int x, y, step;
};
castle bullet[maxn][maxn];
bool vis[maxn][maxn][];
bool check(Node node)
{
return (node.x < || node.y < || node.x > m || node.y > n);
}
void bfs()
{
memset(vis, false, sizeof(vis));
queue<Node> Q;
Node cur, next;
cur.x = cur.y = cur.step = ;
vis[][][] = true;
Q.push(cur);
while (!Q.empty())
{
bool flag;
cur = Q.front();
Q.pop();
if (cur.step > d)
break;
if (cur.x == m && cur.y == n)
{
printf("%d\n", cur.step);
return;
}
for (int i = ; i < ; i++)
{
next.x = cur.x + Next[i][];
next.y = cur.y + Next[i][];
next.step = cur.step + ;
if (check(next))
continue;
//这里前面那个是判断此点是否有碉堡,如果有碉堡的话不能走
if (bullet[next.x][next.y].t == && !vis[next.x][next.y][next.step] && next.step <= d)
{
flag = true;
for (int j = next.x - ; j >= ; j--)//向上找有没有碉堡
{
if (bullet[j][next.y].t != && bullet[j][next.y].dir == 'S')//说明有碉堡.并且朝南
{
int dis = next.x - j;//碉堡与人的距离
if (dis % bullet[j][next.y].v != )//如果不能整除的话,说明子弹在这个点时肯定不是整点,所以直接跳过
break;
int tmp = next.step - dis / bullet[j][next.y].v;//人走的总时间减去第一颗子弹到这需要多少时间
if (tmp < )//如果人到这,子弹还到不了,所以安全,直接跳过
break;
if (tmp % bullet[j][next.y].t == )//如果子弹正好到这,这时人就被打死了
{
flag = false;
break;
}
}
if (bullet[j][next.y].t != )//如果炮塔不朝南的话就直接挡住子弹了
break;
}
if (!flag)
continue;
//下面其他三个方向同理
for (int j = next.x + ; j <= m; j++)
{
if (bullet[j][next.y].t != && bullet[j][next.y].dir == 'N')
{
int dis = j - next.x;
if (dis % bullet[j][next.y].v != )
break;
int tmp = next.step - dis / bullet[j][next.y].v;
if (tmp < )
break;
if (tmp % bullet[j][next.y].t == )
{
flag = false;
break;
}
}
if (bullet[j][next.y].t != )
break;
}
if (!flag)
continue;
for (int j = next.y - ; j >= ; j--)
{
if (bullet[next.x][j].t != && bullet[next.x][j].dir == 'E')
{
int dis = next.y - j;
if (dis % bullet[next.x][j].v != )
break;
int tmp = next.step - dis / bullet[next.x][j].v;
if (tmp < )
break;
if (tmp % bullet[next.x][j].t == )
{
flag = false;
break;
}
}
if (bullet[next.x][j].t != )
break;
}
if (!flag)
continue;
for (int j = next.y + ; j <= n; j++)
{
if (bullet[next.x][j].t != && bullet[next.x][j].dir == 'W')
{
int dis = j - next.y;
if (dis % bullet[next.x][j].v != )
break;
int tmp = next.step - dis / bullet[next.x][j].v;
if (tmp < )
break;
if (tmp % bullet[next.x][j].t == )
{
flag = false;
break;
}
}
if (bullet[next.x][j].t != )
break;
}
if (!flag)
continue;
vis[next.x][next.y][next.step] = true;
Q.push(next);
}
}
}
printf("Bad luck!\n");
}
int main()
{
while (~scanf("%d %d %d %d", &m, &n, &k, &d))
{
char ch;
int a, b, c, d;
memset(bullet, , sizeof(bullet));
for (int i = ; i < k; i++)
{
cin >> ch >> a >> b >> c >> d;
bullet[c][d].dir = ch;
bullet[c][d].t = a;
bullet[c][d].v = b;
}
bfs();
}
return ;
}
HDU 3533 Escape(bfs)的更多相关文章
- 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 S ...
- HDU 3533 Escape BFS搜索
题意:懒得说了 分析:开个no[100][100][1000]的bool类型的数组就行了,没啥可说的 #include <iostream> #include <cstdio> ...
- 【搜索】 HDU 3533 Escape BFS 预处理
要从0,0 点 跑到m,n点 路上会有k个堡垒发射子弹.有子弹的地方不能走,子弹打到别的堡垒就会消失,或者一直飞出边界(人不能经过堡垒 能够上下左右或者站着不动 每步都须要消耗能量 一共同拥有en ...
- 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 ...
- HDU3533 Escape —— BFS / A*算法 + 预处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others) ...
- HDU 3605 Escape (网络流,最大流,位运算压缩)
HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not ...
- Hdu 3605 Escape (最大流 + 缩点)
题目链接: Hdu 3605 Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...
随机推荐
- 【C语言】严格区分大小写
C语言严格区分大小写 一.相关基础知识 二.具体内容 C语言严格区分大小写: 如: int为关键字,INT则为用户标识符,即可定义int INT; int INt; int Int; cha ...
- 求助:对话框下OnInitDialog中使用SetTimer无效
原文地址:http://www.w3c.com.cn/%E6%B1%82%E5%8A%A9%EF%BC%9A%E5%AF%B9%E8%AF%9D%E6%A1%86%E4%B8%8Boninitdial ...
- [BZOJ 2326] [HNOI2011] 数学作业 【矩阵乘法】
题目链接:BZOJ - 2326 题目分析 数据范围达到了 10^18 ,显然需要矩阵乘法了! 可以发现,向数字尾部添加一个数字 x 的过程就是 Num = Num * 10^k + x .其中 k ...
- linux 发布 qt(更新ld命令的路径依赖)
PATH 错误解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such ...
- QT 线程暂停,继续执行的一种实现(有些道理,而且封装了)
注意:本次实现线程的暂停执行主要采用互斥量的方法,如果有更好的实现方法的小伙伴可以在下面留言! 直接插入代码了,由于做的小demo,代码写的可能有点乱,但还算完整. 1 2 3 4 5 6 7 8 9 ...
- 怒刷BZOJ记录(一)1001~1037
我实在是太弱了...不滚粗只能刷BZOJ了...这里来记录每天刷了什么题吧. 2015-7-9 : 1001[BeiJing2006]狼抓兔子 | 最大流练习(呃..其 ...
- 「Poetize6」Candle
描述 蜡烛商店中有10种蜡烛,形状分别是0~9这10个数字,不过对于每种蜡烛,商店的存货量仅有一根.另外,忘川沧月已经有了一个"+"形状的蜡烛.忘川沧月想购买一些蜡烛,使得他的家族 ...
- 【宽搜】ECNA 2015 D Rings (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: 给你一张N*N(N<=100)的图表示一个树桩,'T'为年轮,'.'为空,求每个'T'属于哪一圈年轮,空 ...
- 2013=10=19 ENGLISH 翻译
数据结构习题及答案 严蔚敏_课后习题答案 http://www.doc88.com/p-243584884293.html 273089354 随着女性获得平等权力的趋势,女性日渐增长的经济权力以及为 ...
- [Hibernate] 基本增删查改
本文记录,Java 应用通过 Hibernate 对数据库 MySQL 进行基本的增删改查操作,即CRUD. 本例子的目录结构如下 hibernate.cfg.xml 存储数据库信息,如数据库类型,账 ...
