【题目描述】
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.
HEU的学生正在进行军事训练。
红军和蓝军今天正在打仗。蓝军发现小A是红军的间谍,所以小A必须从蓝军的司令部逃到红军的总部去,战场是一个m * n大小的矩形,蓝军和红军的总部设在(0,0)和(m,n),这意味着小A将分别从(0,0)到(m,n)。下面的图片表示战场的形状和我们稍后使用的指示符号。

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.
蓝军渴望复仇,所以他们尽可能在小A逃离过程种杀死他,蓝军放置了好几个城堡会朝一个方向周期性地射击。小A每秒消耗一个能量无论他是否移动。如果他耗尽了所有的能量或者被击中,他就失败了。小A可以向北、南、东或西移动,每秒钟一个单位。注意,为了不被枪杀,他有时会停下来。
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).
为了简化这个问题,让我们假设小A不能在一秒内停止。他在移动时既不会被射中,也不会阻挡子弹,这意味着一颗子弹只能在整数坐标的位置杀死小A。考虑下面的例子。子弹以每秒3个单位的速度从(0,3)移动到(0,0),小A以每秒1单位的速度从(0,0)移动到(0,1)。那小A就不会被杀了。但是,在上面的例子中,如果子弹每秒移动两个单位,小A将在(0,1)处被杀死。
Now, please tell Little A whether he can escape.
现在,请告诉小A他能否逃脱。

【输入】
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.
对于每个测试样例,第一行有四个整数,m、n、k和d(2<=m,n<=100,0<=k<=100,m+n<=d<=1000)。m和n是战场的大小,k是城堡的数量,d是最初拥有的能量单位。下面的k行描述每个城堡。每一行包含一个字符c和四个整数t、v、x和y。这里c是‘N’,‘S’,‘E’或‘W’,给出了城堡射击的方向, t是周期,v是子弹发射的速度(即每秒通过的单位),(x,y)是城堡的位置。在这里,我们假设,如果一个城堡被其他城堡射击,它将阻止其他人的射击,但不会被摧毁。两颗子弹会在不影响方向和速度的情况下互相穿透。当小A开始逃跑的时候,所有的城堡都开始射击。继续到文件的末尾。

【输出】
If Little A can escape, print the minimum time required in seconds on a single line. Otherwise print “Bad luck!” without quotes.
如果小A可以逃逸,请在一行上以秒为单位打印所需的最短时间。否则就打印“Bad luck!”没有引号。

【样例输入】
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

【样例输出】
9
Bad luck!

题目链接:https://cn.vjudge.net/problem/HDU-3533

一个爆内存爆到心态爆炸的故事
BFS,每次往4个方向看是否会被射死,不会就把下一步进队
内存卡的比较紧,判断的过程写成函数调用会爆,vis不写会爆,vis用int写也会爆,数据特别水,样例都过不了的代码交上去试一下还爆不爆内存竟然都能过

AC代码如下:

#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
static const int MAXN=100;
static const int MAXT=1000;
static const int dx[]={0,0,0,1,-1},dy[]={0,1,-1,0,0};
int m,n,k,d;
struct Castle{int t,v;int kind;
};
struct Node{int x,y;int step;
};
bool vis[MAXT+10][MAXN+10][MAXN+10];
Castle mp[MAXN+10][MAXN+10];
void bfs(Node node)
{queue<Node> Q;Q.push(node);vis[0][0][0]=true;while(!Q.empty()){Node now=Q.front();Q.pop();if(now.x==n && now.y==m && now.step<=d){cout<<now.step<<endl;return;}if(now.step>d){cout<<"Bad luck!"<<endl;return;}for(int i=0;i<=4;i++){Node next;next.x=now.x+dx[i];next.y=now.y+dy[i];next.step=now.step+1;if(!vis[next.step][next.x][next.y] && 0<=next.x && next.x<=n && 0<=next.y && next.y<=m && !mp[next.x][next.y].kind && next.step<=d){bool flag=true;for(int i=next.x-1;i>=0;i--){if(mp[i][next.y].kind){if(mp[i][next.y].kind==2){if((next.x-i)%mp[i][next.y].v==0 && (next.step-(next.x-i)/mp[i][next.y].v)%mp[i][next.y].t==0){flag=false;break;}}break;}}if(!flag)continue;for(int i=next.x+1;i<=n;i++){if(mp[i][next.y].kind){if(mp[i][next.y].kind==1){if((i-next.x)%mp[i][next.y].v==0 && (next.step-(i-next.x)/mp[i][next.y].v)%mp[i][next.y].t==0){flag=false;break;}}break;}}if(!flag)continue;for(int i=next.y-1;i>=0;i--){if(mp[next.x][i].kind){if(mp[next.x][i].kind==3){if((next.y-i)%mp[next.x][i].v==0 && (next.step-(next.y-i)/mp[next.x][i].v)%mp[next.x][i].t==0){flag=false;break;}}break;}}if(!flag)continue;for(int i=next.y+1;i<=m;i++){if(mp[next.x][i].kind){if(mp[next.x][i].kind==4){if((i-next.y)%mp[next.x][i].v==0 && (next.step-(i-next.y)/mp[next.x][i].v)%mp[next.x][i].t==0){flag=false;break;}}break;}}if(!flag)continue;vis[next.step][next.x][next.y]=true;Q.push(next);}}}cout<<"Bad luck!"<<endl;
}
int main()
{std::ios::sync_with_stdio(false);std::cin.tie(0),cout.tie(0);while(cin>>n>>m>>k>>d){memset(mp,0,sizeof(mp));memset(vis,false,sizeof(vis));for(int i=1;i<=k;i++){char ch;int t,v,x,y;cin>>ch>>t>>v>>x>>y;mp[x][y].t=t;mp[x][y].v=v;if(ch=='N')mp[x][y].kind=1;else if(ch=='S')mp[x][y].kind=2;else if(ch=='E')mp[x][y].kind=3;else if(ch=='W')mp[x][y].kind=4;}bfs(Node{0,0,0});}return 0;
}

[kuangbin]专题二 搜索进阶 Escape HDU - 3533【BFS】相关推荐

  1. 专题训练二 搜索进阶 HDU - 3085 Nightmare Ⅱ (双向BFS + 曼哈顿距离)

    HDU - 3085 Nightmare Ⅱ (双向BFS + 曼哈顿距离) Problem Description Last night, little erriyue had a horrible ...

  2. 【搜索进阶】HDU 1667 The Rotation Game

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1667 IDA*的入门题目,状态过多容易超内存,正好体现了IDA*的优势,每次操作移动能使一个数字进入中 ...

  3. 老鱼的-kuangbin专题题解

    kuangbin专题问题一览 专题一 简单搜索 POJ 1321 棋盘问题 POJ 2251 Dungeon Master POJ 3278 Catch That Cow POJ 3279 Flipt ...

  4. kuangbin专题十二 基础DP

    kuangbin专题十二 基础DP A - HDU1024 Max Sum Plus Plus B - HDU1029 Ignatius and the Princess IV C - HDU1069 ...

  5. kuangbin 专题一 简单搜索

    kuangbin 专题一 简单搜索 1.POJ1321棋盘问题[DFS] 代码 自己的想法 2.POJ2251Dungeon Master[三维空间BFS] 代码 自己的想法 3.POJ3278 Ca ...

  6. Kuangbin专题三Dancing Links

    Kuangbin专题三Dancing Links 没写完所有的,因为要去上课了赶紧先预习一下,这就先发出来吧. 跳舞链这东西以前在hihocoder上翻到过,当时看的模模糊糊的,现在好好学一学. 暂时 ...

  7. [kuangbin]专题九 连通图 题解+总结

    kuangbin专题链接:https://vjudge.net/article/752 kuangbin专题十二 基础DP1 题解+总结:https://www.cnblogs.com/RioTian ...

  8. JVM性能调优监控工具专题二:VisualVM基本篇之监控JVM内存,CPU,线程

    2019独角兽企业重金招聘Python工程师标准>>> JVM性能调优监控工具专题二:VisualVM基本篇之监控JVM内存,CPU,线程 博客分类: java jvm 前言: 上一 ...

  9. Android Gradle 自定义Task详解二:进阶

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/78523958 本文出自[赵彦军的博客] 系列目录 Android Gradle使用 ...

最新文章

  1. OpenGL相关网站
  2. mysql show full processlist;_mysql show full processlist 详解
  3. jzoj5702-[gdoi2018day2]滑稽子图【树形dp,二项式定理】
  4. 【转】sharepoint foundation 2013升级sp1补丁后无法使用搜索功能
  5. java 调用 Oracle 存储过程
  6. Python 包管理工具poetry配置国内PyPI镜像源
  7. VC 实现程序只运行一个实例,并激活已运行的程序
  8. 联想拯救者 R720-15ikbn 安装黑苹果 MAC Mojave 10.14.4 efi
  9. MHL技术介绍及接口检测原理
  10. 2012-2022:深度学习十年后是撞墙了吗?Hinton、LeCun、李飞等大佬纷纷发声
  11. 程序员必知的8个Java开源IDE工具!你最钟意哪个?
  12. 公众号滑动图代码_【公众号运营】文章图片滑动效果实现方法
  13. SAP 移动平均价和标准价详细解析
  14. MBRGPT硬盘分区类型属性详解(Win下更改/设置OEM/恢复分区方法)
  15. 计算机图像处理怎么学,计算机图像处理在全息学中的应用
  16. OPENWRT或旁路由如果不能正常使用opkg,正确上网等的一种解决方法
  17. 港科夜闻|香港科技大学副校长汪扬教授接受《经济导报》记者专访,解码大湾区创科基因...
  18. 2021中国宏观经济形势分析与预测年中报告
  19. Bugku - 好多压缩包 - Writeup
  20. php 英文转中文,中文转换成英文

热门文章

  1. NOIP-火柴棒等式
  2. 南明:在大数据发展浪潮中勇立潮头
  3. Sparkstreaming之实时数据流计算实例(Scala)
  4. 图解LeetCode——994. 腐烂的橘子
  5. 碧桂园博智林机器人总部大楼_博智林机器人谷总部大楼A栋完工 未来将成“超强大脑”聚集地...
  6. android强制重启app,android比较便捷的重启APP的方法
  7. 易能机器人_江西全新台达机器人
  8. 制作原生的Win7 PE by AIK
  9. usb rndis主机接收数据错误的分析
  10. 比较著名的.net技术论坛名称(含国外的)