题目:

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. C# textbox 获得焦点

    this.ActiveControl = txt_core;

  2. PHP 之CURL请求封装GET、POST、PUT、DELETE

    /** * @Description: curl请求 * @Author: Yang * @param $url * @param null $data * @param string $method ...

  3. Django - ORM实现用户登陆

    1.路由分发cmdb(app)下urls.py中,建立url与函数对应关系 2.login.html代码: 3.views.py中,login函数,确认是否登陆成功 备注:从前端 获取用户名,密码,在 ...

  4. 浏览器 <html>相关

    若页面需默认用极速核,增加标签:<meta name="renderer" content="webkit">  https://blog.csdn ...

  5. uva 1401

    Neal is very curious about combinatorial problems, and now here comes a problem about words. Knowing ...

  6. 水图(牛客练习赛(DFS搜索))

    题意: 小w不会离散数学,所以她van的图论游戏是送分的 小w有一张n个点n-1条边的无向联通图,每个点编号为1~n,每条边都有一个长度小w现在在点x上她想知道从点x出发经过每个点至少一次,最少需要走 ...

  7. 50.percentiles百分比算法以及网站延时统计

    主要知识点 percentiles的用法     现有一个需求:比如有一个网站,记录下了每次请求的访问的耗时,需要统计tp50,tp90,tp99 tp50:50%的请求的耗时最长在多长时间 tp90 ...

  8. Codeforces 912D - Fishes

    传送门:http://codeforces.com/contest/912/problem/D 本题是一个概率问题——求数学期望. 在一个n×m的方格中,有k个“*”.每个格子里可能有0~1个“*”. ...

  9. 【MFC Programming】 Using Dialog To Set A Correlate Menu

    This blog will show how to display a menu we designed in a dialog. 1.Insert a new dialog& a new ...

  10. ganglia3.7.2,web3.7.1安装

    1.准备安装包 ganglia-3.7.2-2.el6.x86_64.rpm ganglia-gmetad-3.7.2-2.el6.x86_64.rpm ganglia-gmond-3.7.2-2.e ...