HDU3533 Escape
题目:
The 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.
输入:
For 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.
输出:
If Little A can escape, print the minimum time required in seconds on a single line. Otherwise print “Bad luck!” without quotes.
样例:

分析:预处理BFS,坑特别多,简直恶心!(/‵Д′)/~ ╧╧
1.人不能经过碉堡;
2.敌军碉堡可能建到我军基地?!!!
3.子弹碰到碉堡就没了,这里预处理时要注意,碉堡可能在子弹的非击杀点位置,也可能在一秒时子弹出现位置的前面(也就是靠近射出子弹的碉堡)
4.人拥有的能量相当于最大时间
5.人可以禁止不动
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<numeric>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<cctype>
#define PI acos(-1.0)
const int INF = 0x3f3f3f3f;
const int NINF = -INF - ;
typedef long long ll;
using namespace std;
int m, n, k, d;
struct node
{
char dir;
int x, y;
int t, v;
}cas[];
bool vis[][][], used[][][];
bool maze[][];
struct path
{
int x, y;
int time;
};
int dx[] = {, , , , -}, dy[] = {, , , -, };
void ini()
{
for (int i = ; i < k; ++i)
{
if (cas[i].dir == 'N')
{
int flag = ;
for (int j = cas[i].x - ; j >= ; --j)
{
if (maze[j][cas[i].y])
{
flag = j;
break;
}
}
for (int j = ; j <= d; j += cas[i].t)
{
int s = j;
for (int g = cas[i].x - cas[i].v; g >= flag; g -= cas[i].v)
vis[g][cas[i].y][s++] = true;
}
}
else if (cas[i].dir == 'W')
{
int flag = ;
for (int j = cas[i].y - ; j >= ; --j)
{
if (maze[cas[i].x][j])
{
flag = j;
break;
}
}
for (int j = ; j <= d; j += cas[i].t)
{
int s = j;
for (int g = cas[i].y - cas[i].v; g >= flag; g -= cas[i].v)
vis[cas[i].x][g][s++] = true;
}
}
else if (cas[i].dir == 'E')
{
int flag = ;
for (int j = cas[i].y + ; j <= n; ++j)
{
if (maze[cas[i].x][j])
{
flag = j;
break;
}
}
for (int j = ; j <= d; j += cas[i].t)
{
int s = j;
for (int g = cas[i].y + cas[i].v; g <= flag; g += cas[i].v)
vis[cas[i].x][g][s++] = true;
}
}
else if (cas[i].dir == 'S')
{
int flag = ;
for (int j = cas[i].x + ; j <= m; ++j)
{
if (maze[j][cas[i].y])
{
flag = j;
break;
}
}
for (int j = ; j <= d; j += cas[i].t)
{
int s = j;
for (int g = cas[i].x + cas[i].v; g <= flag; g += cas[i].v)
vis[g][cas[i].y][s++] = true;
}
}
}
}
void bfs()
{
queue<path> q;
q.push(path{, , });
memset(used, false, sizeof(used));
used[][][] = true;
while (q.size())
{
path temp = q.front();
q.pop();
if (temp.time >= d) break;
if (temp.x == m && temp.y == n)
{
cout << temp.time << endl;
return;
}
for (int i = ; i < ; ++i)
{
int nx = temp.x + dx[i], ny = temp.y + dy[i];
int nt = temp.time + ;
if (nx >= && nx <= m && ny >= && ny <= n && !vis[nx][ny][nt] && !maze[nx][ny] && !used[nx][ny][nt])
{
used[nx][ny][nt] = true;
q.push(path{nx, ny, nt});
}
}
}
cout << "Bad luck!" << endl;
}
int main()
{
while (cin >> m >> n >> k >> d)
{
memset(vis, false, sizeof(vis));
memset(maze, false, sizeof(maze));
for (int i = ; i < k; ++i)
{
cin >> cas[i].dir >> cas[i].t >> cas[i].v >> cas[i].x >> cas[i].y;
//cout << cas[i].dir << ' ' << cas[i].t << cas[i].v << cas[i].x << cas[i].y << endl;
maze[cas[i].x][cas[i].y] = true;
}
/*for (int i = 0; i <= m; ++i)
{
for (int j = 0; j <= n; ++j)
cout << maze[i][j] << ' ';
cout << endl;
}
cout << endl;*/
if (maze[m][n])
{
cout << "Bad luck!" << endl;
continue;
}
ini();
/*for (int i = 0; i <= m; ++i)
{
for (int j = 0; j <= n; ++j)
cout << vis[i][j][2] << ' ';
cout << endl;
}*/
bfs();
}
return ;
}
HDU3533 Escape的更多相关文章
- HDU3533 Escape —— BFS / A*算法 + 预处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others) ...
- HDU3533(Escape)
不愧是kuangbin的搜索进阶,这题没灵感写起来好心酸 思路是预处理所有炮台射出的子弹,以此构造一个三维图(其中一维是时间) 预处理过程就相当于在图中增加了很多不可到达的墙,然后就是一个简单的bfs ...
- 【HDU - 3533】Escape(bfs)
Escape Descriptions: 一个人从(0,0)跑到(n,m),只有k点能量,一秒消耗一点,在图中有k个炮塔,给出炮塔的射击方向c,射击间隔t,子弹速度v,坐标x,y问这个人能不能安全到 ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- 简单明了区分escape、encodeURI和encodeURIComponent
一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...
- c#模拟js escape方法
public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ...
- 【BZOJ-1340】Escape逃跑问题 最小割
1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 264 Solved: 121[Submit] ...
- LYDSY热身赛 escape
Description 给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上矩形的行 ...
- javascript escape()函数和unescape()函数
javascript escape()函数和unescape()函数 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法: escape(string) stri ...
随机推荐
- (转)Arcgis for Js之Graphiclayer扩展详解
http://blog.csdn.net/gisshixisheng/article/details/41208185 在前两节,讲到了两种不同方式的聚类,一种是基于距离的,一种是基于区域范围的,两种 ...
- eclipse版本和jdk的版本兼容问题
eclipse也是有版本的,当版本过低时,无法兼容高版本的jdk 项目中用的是jdk1.8,但是低版本的eclipse只能选到jdk1.7,导致java文件在编译的过程中,不识别1.8版本jdk的语法 ...
- ubuntu14.0开机guest账号禁用方法
在终端里进入/usr/share/lightdm/lightdm.conf.d/目录 sudo vim 50-unity-greeter.conf 然后在文件里输入: [SeatDefaults] a ...
- final关键字用法
Java关键字final有“这是无法改变的”或者“终态的”含义,它可以修饰非抽象类.非抽象类成员方法和变量. final类不能被继承,没有子类,final类中的方法默认是final的. final方法 ...
- c++ map迭代器
#include <stdio.h> #include <map> using namespace std; int main(){ map<int, int> m ...
- 模拟Spring容器的getBean方法(Maven工程)
Spring容器的getBean方法是通过反射机制实现的,下面的测试程序模拟getBean的实现原理. 步骤一:pom.xml文件配置解析XML文件的dom4j.jar 步骤二:XML文件中配置bea ...
- img标签和background-image的区别和具体使用时机
最近在使用图片过程中,纠结到底使用img标签还是使用background-image属性,翻阅资料和百度后作出下列理解. 简单来说img是内容部分的东西,background-image是修饰性的东西 ...
- linux 头文件和库文件的设置
GCC/G++会查找系统默认的include和link的路径,以及自己在编译命令中指定的路径.自己指定的路径就不说了,这里说明一下系统自动搜索的路径. [1]include头文件路径 除了默认的/us ...
- 倍增/线段树维护树的直径 hdu5993/2016icpc青岛L
题意: 给一棵树,每次询问删掉两条边,问剩下的三棵树的最大直径 点10W,询问10W,询问相互独立 Solution: 考虑线段树/倍增维护树的直径 考虑一个点集的区间 [l, r] 而我们知道了有 ...
- MySql数据库优化可以从哪几个方面进行?
1.选取最适用的字段属性 MySQL可以很好的支持大数据量的存取,但是一般说来,数据库中的表越小,在它上面执行的查询也就会越快.因此,在创建表的时候,为了获得更好的性能,我们可以将表中字段的宽度设得尽 ...