题目

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.

Input

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.

Output

If Little A can escape, print the minimum time required in seconds on a single line. Otherwise print “Bad luck!” without quotes.

Sample Input

4 4 3 10
N 1 1 1 1
W 1 1 3 2
W 2 1 2 4
4 4 3 10
N 1 1 1 1
W 1 1 3 2
W 1 1 2 4

Sample Output

9
Bad luck!

题目链接

HDU_3533_Escape

参考链接

HDU_3533_Escape_Discuss Board

题目简述

三维判重的迷宫搜索问题,读完题面有以下几点需要注意:

1. 不能走到敌人的城堡!即使堡垒此时不往外发射子弹,也不可以走到敌人的堡垒!

2.这是一个(n+1)*(m+1)大小的迷宫,不是n*m大小的迷宫。

3.题面图中的n、m写反了!(一开始没注意,可以通过样例。真按照图中做,反而通过不了样例了)。

4.如果此时站在此点上被射击到,需要满足哪些条件。

5.Little A可以朝东西南北四个方向走,也可以站在原地不动。

程序分析

int castle_num/**城堡数量**/,n,m,k,d;
int zx[]={-1,0,1,0,0};
int zy[]={0,1,0,-1,0};/**方向数组**/
bool visit[maxn][maxn][maxn];
struct MAP
{
    int castle;
    int sour_bul[4];/**Source of bullets**/
}Map[maxn][maxn];

struct Castle
{
    char dir/**direction**/;
    int t/**周期**/,v/**速度**/,x,y;
}ca[1005];/**城堡数组**/

struct Node/**状态**/
{
    int x,y,time;
};

void init()/**初始化数组**/
bool be_shot(Node a)/**判断该状态是否会吃子弹**/
void mark()/**预处理**/
int bfs()/**搜索**/

程序

#include<iostream>
#include<stdio.h>
#include<queue>
#include<cmath>
#include<string.h>
#include<math.h>
using namespace std;
#define maxn 105
int castle_num,n,m,k,d;
int zx[]={-1,0,1,0,0};
int zy[]={0,1,0,-1,0};bool visit[maxn][maxn][maxn];struct MAP
{int castle;int sour_bul[4];/**Source of bullets**/
}Map[maxn][maxn];struct Castle
{char dir/**direction**/;int t/**周期**/,v/**速度**/,x,y;
}ca[1005];struct Node
{int x,y,time;
};void init()
{memset(visit,0,sizeof(visit));for(int i=0;i<=n;i++){for(int j=0;j<=m;j++){Map[i][j].castle=-1;for(int k=0;k<4;k++)Map[i][j].sour_bul[k]=-1;}}
}bool be_shot(Node a)
{if(Map[a.x][a.y].castle!=-1/*&&a.time%ca[Map[a.x][a.y].castle].t==0**/)return true;for(int i=0;i<4;i++){int num=Map[a.x][a.y].sour_bul[i];if(num!=-1){int dist=abs(ca[num].x-a.x)+abs(ca[num].y-a.y);if(dist%ca[num].v==0){int tim=a.time-dist/ca[num].v;if(tim>=0&&tim%ca[num].t==0)return true;}}}return false;
}void mark()
{for(int i=0;i<castle_num;i++)Map[ca[i].x][ca[i].y].castle=i;for(int i=0;i<castle_num;i++){int direc,xx,yy;if(ca[i].dir=='N') direc=0;else if(ca[i].dir=='E') direc=1;else if(ca[i].dir=='S') direc=2;else if(ca[i].dir=='W') direc=3;for(xx=ca[i].x,yy=ca[i].y;;xx+=zx[direc],yy+=zy[direc]){if(xx<0||xx>n||yy>m||yy<0)break;if((xx!=ca[i].x||yy!=ca[i].y)&&Map[xx][yy].castle!=-1)break;Map[xx][yy].sour_bul[direc]=i;}}
}int bfs()
{Node start;start.time=0;start.x=0;start.y=0;queue<Node>q;q.push(start);visit[start.x][start.y][start.time]=true;while(!q.empty()){Node now=q.front();q.pop();for(int i=0;i<5;i++){Node next=now;next.time++;next.x+=zx[i];next.y+=zy[i];if(next.x>=0&&next.x<=n&&next.y>=0&&next.y<=m&&!visit[next.x][next.y][next.time]){if(!be_shot(next)&&next.time<=d){visit[next.x][next.y][next.time]=true;q.push(next);if(next.x==n&&next.y==m)return next.time;}}}}return -1;
}int main()
{while(scanf("%d%d%d%d",&n,&m,&k,&d)!=EOF){init();castle_num=k;char c;for(int i=0;i<castle_num;i++){scanf("%c",&c);scanf("%c",&ca[i].dir);scanf("%d%d%d%d",&ca[i].t,&ca[i].v,&ca[i].x,&ca[i].y);}mark();int answer=bfs();if(answer==-1)printf("Bad luck!\n");elseprintf("%d\n",answer);}return 0;
}

HDU 3533 Escape (预处理+BFS)相关推荐

  1. HDU - 3533 Escape(预处理+A*)

    题目链接:点击查看 题目大意:题意我感觉描述的很不清楚..是看网上其他大佬的博客总结来的,大意就是我们要从点(0,0)走到点(n,m),然后在一些地方设置了炮塔(炮塔视为墙),可以向一个方向周期性地发 ...

  2. HDU - 1495 非常可乐(BFS,数学)

    HDU - 1495 非常可乐(BFS,数学) 巨佬的数学解法 #include<iostream> using namespace std; int gcd(int a,int b) { ...

  3. CSU2112 Wells的明星生活 预处理BFS二分

    为涛爷约会女朋友加油!\(` o ')/ 题目非常长了: Wells和小姐姐正在浪漫的约会呢,Wells猛然得到最新消息,有若干狗仔团队正闻讯蜂拥而来(Wells毕竟还是蛮很有名气的嘛)-- Well ...

  4. [kuangbin]专题二 搜索进阶 Escape HDU - 3533【BFS】

    [题目描述] The students of the HEU are maneuvering for their military training. The red army and the blu ...

  5. HDU 4856 Tunnels(BFS+状压DP)

    HDU 4856 Tunnels 题目链接 题意:给定一些管道.然后管道之间走是不用时间的,陆地上有障碍.陆地上走一步花费时间1,求遍历全部管道须要的最短时间.每一个管道仅仅能走一次 思路:先BFS预 ...

  6. nyoj999 师傅又被妖怪抓走了 (预处理+bfs+状态压缩)

    题目999 题目信息 执行结果 本题排行 讨论区 师傅又被妖怪抓走了 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 话说唐僧复得了孙行者,师徒们一心同体,共诣西方.自宝 ...

  7. poj3669 Meteor Shower(预处理+bfs)

    https://vjudge.net/problem/POJ-3669 先给地图a[][]预处理每个位置被砸的最小时间.然后再bfs. 纯bfs,还被cin卡了下时间.. 1 #include< ...

  8. HDU1429胜利大逃亡(续)HDU 1885 Key Task BFS+状态压缩+水

    HDU1429 只有10把钥匙 1<<10足够了 标记用三维数组 用Linux好不习惯 继续克服- #include <stdio.h> #include <string ...

  9. HDU 2653 (记忆化BFS搜索+优先队列)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2653 题目大意:迷宫中有普通点和陷阱.其中普通点可以走可以飞,但是陷阱只能飞.走耗时1,飞耗时2.但 ...

  10. HDU 2102 题解(BFS 广度优先搜索 练习题)

    原题链接,但是HDU现在校外提交需要审核 欢迎来 SCPC OJ提交 知识点 : BFS(广搜/宽搜) 原题: 描述: 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生 ...

最新文章

  1. 存在就不插入_DOM 插入节点和三个Child方法
  2. webservice(二)简单实例
  3. Android通过JNI调用驱动程序(完全解析实例)
  4. linux如何查看硬件驱动,linux查看硬件信息及驱动设备相关整理
  5. Levenshtein Distance算法(编辑距离算法)
  6. 真正的高阶特征交叉:xDeepFM与DCN-V2
  7. 获取当前项目的根目录的方法
  8. php curl使用详解
  9. 博微三维技术篇【七】——生态数据兼容
  10. Codeforces 1194B+1194D
  11. MovieClip详解
  12. 问题 A: Hz的宝箱
  13. javaSE 笔记全!
  14. 南昌大学计算机考研学硕,南昌大学电子信息工程专硕考研心得
  15. 负数在计算机中的编码形式
  16. 【BZOJ2754】【SCOI2012】喵星球上的点名(后缀数组)
  17. 《软件工程》知识点复习总结
  18. aopalliance.jar是什么?
  19. springCloud——Dalston.SR5升级到Greenwich.SR2
  20. 设备模型管理对象kobject分析

热门文章

  1. 水调歌头.明月几时有 小儿拼音版
  2. django 分拆views 提示 module ‘app001.views‘ has no attribute ‘xxx‘
  3. python 列表长度_python求列表长度
  4. 怎样用微信与电脑连接服务器,怎么使用WebSocket进行微信小程序远程控制电脑屏幕?...
  5. BZOJ 2339 卡农(组合数学)
  6. 计算机网络(2.10)物理层- 宽带接入技术-ADSL 技术
  7. matlab有限域多项式除法_第四章多项式和有限域.ppt
  8. 主机当前没有管理网络冗余
  9. 【读书笔记】《读懂孩子的心》——重新了解完整的自己
  10. 目标追踪(一)环境搭建