题目链接:Escape HDU - 3533

===================================================

Escape

Time Limit: 1000MS
Memory Limit: 32768 kB

Description

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!

===================================================

算法:A* BFS

思路:

函数 用步数 + 与终点的曼哈顿距离(因为只是四方向行进)

现在感觉做这些模拟题,读题真的是关键中的关键,很容易踩坑,然后纠结很久;

难点关键:首先,炮台会帮你挡子弹;然后二维坐标上存在时间维度,这里需要用到三维数组记录状态,因为子弹的原因,因为最糟糕情况就是你这一时间被一个子弹挡住去路,

然后下一时间你又被挡住去路,并且当前位置会被子弹打到,需要往回走;所以单纯二维不够用;三维能用的又一原因在于题目存在体力值(相当于时间,用完就跳出),所以不会存在死循环;

这里子弹模拟计算,又是另一难点。看了其他人代码,有些是走到当前位置再去判断是否会被四周打到。

然后另一种更优方法就是用3维数组去记录子弹的动作,发挥想象力,就像是每一个时间维度下的二维就是幻灯片。然后你记录这些子弹轨迹,这样理解就简单多了。

===================================================

#include <iostream>
#include <cmath>
#include <cstring>
#include <queue>using namespace std;bool vis[102][102][1001],bullet[102][102][1001],ditu[102][102];
int m,n,k,d;
int xx[] = {0,0,-1,1,0};
int yy[] = {-1,1,0,0,0};struct castle{int c,v,t,x,y;
}ca[102];struct node{int x,y,step,f;bool operator<(const node &a)const{return f>a.f;}node(int a,int b,int c) {x = a,y = b,step = c;f = step + abs(x - m) + abs(y - n);};
};int checkD(char ch){switch(ch){case 'N':return 2;case 'S':return 3;case 'E':return 1;case 'W':return 0;}return -1;
}bool check(int x,int y){return x>=0&&x<=m&&y>=0&&y<=n;
}void init(){memset(bullet,false,sizeof bullet);for(int i=1;i<=k;i++){int c = ca[i].c , v = ca[i].v,t = ca[i].t;for(int j=1;;j++){int x = ca[i].x + xx[c]*j , y = ca[i].y + yy[c]*j;if(ditu[x][y]||!check(x,y)) break;if(j%v==0){for(int z=0;z+j/v<=d;z+=t){//cout<<i<<" "<<x<<" "<<y<<" "<<z+j/v<<endl;bullet[x][y][z+j/v] = true;}}}}
}bool bfs(){memset(vis,false,sizeof vis);priority_queue<node> q;q.push(node(0,0,0));vis[0][0][0] = true;while(!q.empty()){node p = q.top();q.pop();//cout<<p.x<<" "<<p.y<<" "<<p.step<<endl;if(p.step>d) continue;if(p.x==m&&p.y==n){cout<<p.step<<endl;return true;}for(int i=0;i<5;i++){int x = p.x + xx[i],y = p.y + yy[i] , step = p.step + 1;if(!check(x,y)||ditu[x][y]||vis[x][y][step]||bullet[x][y][step]) continue;vis[x][y][step] = true;q.push(node(x,y,step));}}return false;
}int main()
{while(cin>>m>>n>>k>>d){memset(ditu,false,sizeof ditu);char ch;int t,v,x,y;for(int i=1;i<=k;i++){cin>>ch>>t>>v>>x>>y;ditu[x][y] = true;ca[i].c = checkD(ch);ca[i].t = t,ca[i].v = v , ca[i].x = x, ca[i].y = y;}//for(int i=1;i<=k;i++) cout<<ca[i].c<<" "<<ca[i].t<<" "<<ca[i].v<<" "<<ca[i].x<<" "<<ca[i].y<<endl;init();/*for(int i=0;i<=d;i++){for(int j=0;j<=m;j++){for(int z=0;z<=n;z++) cout<<bullet[j][z][i]<<" ";cout<<endl;}cout<<endl;}*/if(!bfs()) puts("Bad luck!");}return 0;
}

Escape HDU - 3533相关推荐

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

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

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

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

  3. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  4. 算法学习经典例题整理

    陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...

  5. kuangbin带你飞 专题1-23 题单

    kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...

  6. 老鱼的-kuangbin专题题解

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

  7. 解题报告:【kuangbin带你飞】专题十一 网络流

    目录 A.POJ 3436 ACMComputerFactoryACM\ Computer\ FactoryACM Computer Factory[省选/NOI- ] B.POJ 3281 Dini ...

  8. [kuangbin]各种各样的题单

    [kuangbin]各种各样的题单 专题1 简单搜索 POJ 1321 POJ 2251 POJ 3278 POJ 3279 POJ 1426 POJ 3126 POJ 3087 POJ 3414 F ...

  9. 杭电OJ分类题目(4)-Graph

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(4) HDU Graph Theory - U ...

  10. 杭电OJ分类题目(1)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(1) HDU Introduction HDU ...

最新文章

  1. zookeeper 和 dubbo 配置
  2. uni-app 请求封装
  3. 密码技术--椭圆曲线算法EDCSA数字签名及Go语言应用
  4. (二)Python 学习第二天--爬5068动漫图库小案例
  5. Gridview 手动排序实现
  6. SaaS 通识系列 1:云计算是什么
  7. dynamic programming 学习
  8. oracle怎么定时执行存储过程6,Oracle中如何定时调用存储过程
  9. 【转】“你不适合做程序员”
  10. gitolite安装及配置教程centos7
  11. Bailian2723 不吉利日期(POJ NOI0113-02)【日期计算】
  12. python中pass的使用_pass语句如何在Python项目中使用
  13. Qt 点击任意子控件,背景选中 选中背景
  14. 5行python代码帮你搞定百度文库复制问题
  15. CodeBlock 常用快捷键
  16. pg和MySQL读性能_[评测]低配环境下,PostgresQL和Mysql读写性能简单对比
  17. 密码忘了怎么办? 5种破密方法轻松搞定
  18. java项目编码问题解决
  19. 分享5款堪称神器的免费软件,建议先收藏再下载
  20. python程序编译错误_Python编译错误集锦

热门文章

  1. django urls import views报错
  2. 软件体系结构——面向对象风格
  3. mysql 临时表权限_MySQL临时表浅析
  4. 棒球游戏 android,真正的职业棒球比赛
  5. cad卸载不干净_Mac软件卸载不干净?你可以试试AppCleaner
  6. 定义并测试一个代表员工的Employee类。
  7. VMware 16 Pro安装MacOS Mojava 10.14
  8. 汇报措辞:你懂得如何向领导汇报吗(审阅、审批、审阅、批示、查阅)?
  9. 计算机音乐公子,抖音公子在等谁是什么梗 公子在等谁背景音乐《心机》
  10. xgene:之ROC曲线、ctDNA、small-RNA seq、甲基化seq、单细胞DNA, mRNA