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 ...
随机推荐
- js 时间 Fri Dec 12 2014 08:00:00 GMT+0800
第一种var d = new Date('Fri Dec 12 2014 08:00:00 GMT+0800'); ) + '-' + d.getDate() + ' ' + d.getHours() ...
- .net core发布程序
这里说的是,和.net core运行库一起发布,所以,目标运行系统,可以不安装.net core也能运行 1.project.json 把dependencies里面的type删除掉,后面加入&quo ...
- @viewChild
https://www.cnblogs.com/mttcug/p/8004359.html
- demo_static_resrouce
环境 win10 + webstorm 2019.1.3 + node 12.x + yarn 实现的的功能 基本的js打包(支持规范:ES6 module | requirejs | commonj ...
- common_functions.h:64:24: error: token ""__CUDACC_VER__ is no longer supported.
问题在复现工程https://github.com/google/hdrnet时出现. 现象: 解决: TensorFlow版本问题,升级到版本1.10.0之后,问题解决.
- 【第8篇】:Python之面向对象
python之--------封装 一.封装: 补充封装: 封装: 体现在两点: 1.数据的封装(将数据封装到对象中) obj = Foo('宝宝',22) 2.封装方法和属性,将一类操作封装到一个类 ...
- raspberry 重新烧录后的设置
raspberry初学者在使用的时候经常遇到各种问题,常常重新烧录系统,现在把新系统的常用配置和安装内容整理一下,避免自己忘记 1.安装常用软件包: sudo apt-get gedit sudo a ...
- 第三节:numpy之数组数学运算
- Codeforces Round #400 (Div. 1 + Div. 2, combined)——ABCDE
题目戳这里 A.A Serial Killer 题目描述似乎很恶心,结合样例和样例解释猜测的题意 使用C++11的auto可以来一手骚操作 #include <bits/stdc++.h> ...
- hdu_1003_Max Sum_201311271630
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...