题目:

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. java 类名.this

    类名为this的限定词. 相对于内部类:有多个this: 1.内部类本身的this: 2.内部类的环境类的this: 类名.this,就是为了对这些this指针的指向做出限定. 区别于类名.class ...

  2. 为.net mvc core 启用 https

    引用nuget包:Microsoft.AspNetCore.Server.Kestrel.Https这是一个服务器测试ssl密钥,密码如代码里面所示 using System; using Syste ...

  3. centos vm 桥接 --网络配置

    /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=none BROADCAST=192.168.1.255 HWADDR= ...

  4. 文章或者观点说说等点赞功能实现(thinkphp)

    前端的代码: <!-- 点赞 --> <div class='btm'><a class='zan' id="{$article.id}" href= ...

  5. 《Mysql - 到底可不可以使用 Join ?》

    一:Join 的问题? - 在实际生产中,使用 join 一般会集中在以下两类: - DBA 不让使用 Join ,使用 Join 会有什么问题呢? - 如果有两个大小不同的表做 join,应该用哪个 ...

  6. 27.7 并行语言集成查询(PLinq)

    static void Main() { ObsoleteMethods(Assembly.Load("mscorlib.dll")); Console.ReadKey(); } ...

  7. How To : Modify ASM SYS password using asmcmd 11g R2 and upper

    修改RAC 11gR2及以上版本的ASM的SYS的密码方法 [grid]$ asmcmd ASMCMD> orapwusr --modify --password sys Enter passw ...

  8. Git ——Tool

    Git: 何为Git: Git 是一个可以实时记录文件变化.维护文件的安全的一个仓库! Git仓库是由** Linux 系统之父 Linus Torvalds ** 创建的一个开源 的软件!Githu ...

  9. 使用PHP操作MongoDB数据库

    1.连接MongoDB数据库(在已安装php-mongodb扩展的前提下) $config = "mongodb://{$user}:{$pass}@{$host}:{$port}" ...

  10. 一次vue-cli 2.x项目打包优化经历(优化xlsx插件)

    一.分析各模块打包后大小 用vue-cli创建的项目,已经集成 webpack-bundle-analyzer.详见文件 build/webpack.prod.conf.js,代码如下: if (co ...