题目:

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的更多相关文章

  1. HDU3533 Escape —— BFS / A*算法 + 预处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others)  ...

  2. HDU3533(Escape)

    不愧是kuangbin的搜索进阶,这题没灵感写起来好心酸 思路是预处理所有炮台射出的子弹,以此构造一个三维图(其中一维是时间) 预处理过程就相当于在图中增加了很多不可到达的墙,然后就是一个简单的bfs ...

  3. 【HDU - 3533】Escape(bfs)

    Escape  Descriptions: 一个人从(0,0)跑到(n,m),只有k点能量,一秒消耗一点,在图中有k个炮塔,给出炮塔的射击方向c,射击间隔t,子弹速度v,坐标x,y问这个人能不能安全到 ...

  4. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  5. 简单明了区分escape、encodeURI和encodeURIComponent

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

  6. c#模拟js escape方法

    public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ...

  7. 【BZOJ-1340】Escape逃跑问题 最小割

    1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 264  Solved: 121[Submit] ...

  8. LYDSY热身赛 escape

    Description 给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上矩形的行 ...

  9. javascript escape()函数和unescape()函数

    javascript escape()函数和unescape()函数 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法: escape(string) stri ...

随机推荐

  1. js 输入框只能输入 1-7 的数字

    $jq(function () { $jq("#XSCM_WORKDAY").keyup(function () { //如果输入非数字,则替换为'',如果输入数字,则在每4位之后 ...

  2. codevs1231 最优布线问题

    1231 最优布线问题 题目描述 Description 学校需要将n台计算机连接起来,不同的2台计算机之间的连接费用可能是不同的.为了节省费用,我们考虑采用间接数据传输结束,就是一台计算机可以间接地 ...

  3. Luogu P1892 [BOI2003]团伙

    P1892 [BOI2003]团伙 题目描述 1920年的芝加哥,出现了一群强盗.如果两个强盗遇上了,那么他们要么是朋友,要么是敌人.而且有一点是肯定的,就是: 我朋友的朋友是我的朋友: 我敌人的敌人 ...

  4. Linux - redis-cluster搭建

    目录 Linux - redis-cluster搭建 Linux - redis-cluster搭建 1.准备6个数据库节点,也就是6个redis实例,也就是6个配置文件 配置文件如下 redis-7 ...

  5. HDU 5343 MZL's Circle Zhou

    MZL's Circle Zhou Time Limit: 1000ms Memory Limit: 131072KB This problem will be judged on HDU. Orig ...

  6. MG loves string

    MG loves string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others ...

  7. [POJ1456]Supermarket(贪心 + 优先队列 || 并查集)

    传送门 1.贪心 + 优先队列 按照时间排序从前往后 很简单不多说 ——代码 #include <queue> #include <cstdio> #include <i ...

  8. 清北学堂模拟赛d6t2 刀塔

    分析:看到最小值最大就很显然是二分了吧,二分一下最小值,把小于它的数给删掉,然后看每个数向左边能延伸多长,往右边能延伸多长,最后统计一下有没有可行答案就可以了. #include <cstdio ...

  9. 【学QT】2 - QT/E环境的建立

    Arm-Linux嵌入式QT/E环境的建立(qt/e 3.x系列)          QT/E 3.x系列比QT/E 2.x系列有非常大的改进,大大提高了开发进度,不再使用tmake,安装也更简单.但 ...

  10. 用循环链表实现Josephus问题

    Josephus问题:设有n个人围坐在一个圆桌周围,现从第s个人开始报数,数到第m的人出列,然后从出列的下一个人重新开始报数,数到第m的人又出列.如此反复直到所有的人全部出列为止. 思路:构建一个没有 ...