题目链接

Problem 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!

大致题意
给你一个n*m矩阵,接下来k和d表示塔的数量和d的时间
接下来k行,每行s,t,v,x,y,分别表示塔防的攻击方向,攻击时间间隔,子弹速度,和塔防坐标,问是否可以在不被击中的情况下从左上角走到左下角

具体思路
1.走的时候可以停留在原地浪费一秒
2.不能走到塔的格子
3.当子弹和人同时到同一个格子的时候认为被攻击
4.子弹飞到格子的时间默认整数,小数就是打不到人
5,塔可以挡子弹
其实只要计算出在d的时间内,这个矩阵上子弹会飞到哪个格子就可以了,一个bfs的预处理去存取子弹的出现格子与时间即可
注意:标记用bool的数组,int本人爆内存了好几发,注意多组数据初始化标记,这个我又WA了两个,很头疼

#include<bits/stdc++.h>
using namespace std;
struct T
{int s,t,v,x,y;
}turret[105];
struct node
{int x,y,times;
};
int n,m,k,d;
int change[5][2]={{-1,0},{1,0},{0,1},{0,-1},{0,0}};
bool flags[105][105][1005],pot[105][105],used[105][105][1005];
void pre()
{memset(flags,0,sizeof(flags));for (int i=0;i<k;i++){for (int j=0;j<=d;j=j+turret[i].t){for (int k=1;;k++){int x=turret[i].x+change[turret[i].s][0]*k;int y=turret[i].y+change[turret[i].s][1]*k;if (x<0||x>n||y<0||y>m||pot[x][y]){break;}if (k%turret[i].v==0){flags[x][y][j+k/turret[i].v]=true;}}}}
}
int bfs()
{memset(used,0,sizeof(used));queue<node>dui;while (!dui.empty()){dui.pop();}node start;start.times=start.x=start.y=0;used[0][0][0]=true;dui.push(start);while (!dui.empty()){node now;now=dui.front();dui.pop();if (now.times>d){return -1;}if (now.x==n&&now.y==m){return now.times;}for (int i=0;i<5;i++){node next;next.x=now.x+change[i][0];next.y=now.y+change[i][1];next.times=now.times+1;if (next.x>=0&&next.x<=n&&next.y>=0&&next.y<=m&&!pot[next.x][next.y]&&!flags[next.x][next.y][next.times]&&!used[next.x][next.y][next.times]){used[next.x][next.y][next.times]=1;dui.push(next);}}}return -1;
}
int main()
{while (scanf("%d %d %d %d%*c",&n,&m,&k,&d)!=EOF){memset(pot,0,sizeof(pot));char s,v,x,y;for (int i=0;i<k;i++){scanf("%c %d %d %d %d%*c",&s,&turret[i].t,&turret[i].v,&turret[i].x,&turret[i].y);if(s=='N'){turret[i].s=0;}if(s=='S'){turret[i].s=1;}if(s=='E'){turret[i].s=2;}if(s=='W'){turret[i].s=3;}pot[turret[i].x][turret[i].y]=1;}pre();int ans=bfs();if (ans==-1){printf("Bad luck!\n");}else{printf("%d\n",ans);}}return 0;
}

HDU 3533 Escape相关推荐

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

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

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

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

  3. HDU [P3605] Escape

    二分图多重匹配 改进版的匈牙利,加入了一个cnt数组作为找到增广路的标志 本题有一个重要的优化见注释 #include <iostream> #include <cstdio> ...

  4. HDU - 3605 Escape(二分图多重匹配-网络流最大流+思维建边+状态压缩)

    题目链接:点击查看 题目大意:到世界末日了,现在人们要逃离去其他的星球,现在给出n个人以及m个星球,再给出每个人可以前往的星球,最后给出每个星球的容量,题目问最多能让多少个人逃离 题目分析:这个题读完 ...

  5. HDU 3605 Escape【最大流】

    题意:有n个人,m个星球,要搬家,一些人有特定喜欢的星球,让尽量多的人到星球. 输入n,m 输入n*m矩阵表示 i 人是否喜欢 j 星球 输入m个数字表示星球对人的容量 直接建图会超时,然后我们发现m ...

  6. kuangbin带你飞专题合集

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

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

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

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

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

  9. 老鱼的-kuangbin专题题解

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

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

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

最新文章

  1. Windows Server 2012 之配置AD DS
  2. asp.net 安装element ui_Vue组件库系列三:打造属于自己的 UI 库文档(新版本的方案)...
  3. TCP/IP详解--学习笔记(11)-TCP交互数据流,成块数据流
  4. 皮一皮:到底是土还是士...
  5. 青龙羊毛——广汽三菱(搬运)
  6. android系统release签名
  7. 【PAT】A1028 List Sorting
  8. vs2019中如何创建qt项目_VS2019创建新项目居然没有.NET Core3.0的模板?
  9. 开机未发现nvidia控制面板_Windows10或者其他操作系统开机提示“未发现NVIDIA控制面板,从Microsoft Store中安装NVIDIA控制面板”的解决办法...
  10. SQL server 数据库 (函数篇 2)
  11. dingtalk 推送手机号信息 golang_Python学习第九十六天:Python调用钉钉机器人推送消息...
  12. 搭建VMware6.5+Win2003 MSCS群集实验环境
  13. 乘风破浪:LeetCode真题_019_Remove Nth Node From End of List
  14. 金融直播三大常用场景一文解析
  15. 华为虚拟专网客户端SecoClient报错“接受返回码超时”故障
  16. python人脸识别代码实现
  17. 微信“小程序”来了 Webpower教您如何做二维码营销
  18. 【字体分享】这么Q萌的字母设计你肯定没见过
  19. 微信小程序怎么开店铺
  20. 2020杭电计算机考研经验帖

热门文章

  1. 算法笔记(9)-随机森林算法及Python代码实现
  2. 手机数据连接接入(外网)访问xampp
  3. 快速部署使用tensorRT加速推理(trt,onnx)
  4. ElasticSearch索引模板(template)操作:创建、查询、修改、删除
  5. Linux的tomcat文件夹下没有startup.sh
  6. Unity实现3D模式下的摄像机视角控制
  7. 雅虎将提供PHP网站托管服务
  8. 卷积神经网络中的“池化层”
  9. android自定义listview 显示数组,android TextView控件如何显示Listview数组内容到一个Textview控件上?...
  10. 升级mojava之后git失效的问题