HDU3533(KB2-D)
Escape
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1407 Accepted Submission(s): 392
Problem Description
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
All castles begin to shoot when Little A starts to escape.
Proceed to the end of file.
Output
Sample Input
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
Bad luck!
Source
//2017-03-09
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue> using namespace std; const int N = ;
int grid[N][N];
bool vis[N][N][];
int n, m, k, d, ans;
int dx[] = {, , , -, };
int dy[] = {, , -, , };
struct castle
{
char dir;
int t, v;
}cas[N];
struct node
{
int x, y, step;
void setNode(short x, short y, short step)
{
this->x = x;
this->y = y;
this->step = step;
}
}; bool judge(int x, int y, int Time)
{
for(int i = y-; i >= ; i--)
{
if(grid[x][i]){
if(cas[grid[x][i]].dir == 'E' && (y-i)%cas[grid[x][i]].v == && (Time-(y-i)/cas[grid[x][i]].v)>= && (Time-(y-i)/cas[grid[x][i]].v)%cas[grid[x][i]].t == )
return false;
}
if(grid[x][i])break;
}
for(int i = y+; i <= m; i++){
if(grid[x][i])
if(cas[grid[x][i]].dir == 'W' && (i-y)%cas[grid[x][i]].v == && (Time-(i-y)/cas[grid[x][i]].v)>= && (Time-(i-y)/cas[grid[x][i]].v)%cas[grid[x][i]].t == )
return false;
if(grid[x][i])break;
} for(int i = x-; i >= ; i--){
if(grid[i][y])
if(cas[grid[i][y]].dir == 'S' && (x-i)%cas[grid[i][y]].v == && (Time-(x-i)/cas[grid[i][y]].v)>= && (Time-(x-i)/cas[grid[i][y]].v)%cas[grid[i][y]].t == )
return false;
if(grid[i][y])break;
}
for(int i = x+; i <= n; i++){
if(grid[i][y])
if(cas[grid[i][y]].dir == 'N' && (i-x)%cas[grid[i][y]].v == && (Time-(i-x)/cas[grid[i][y]].v)>= && (Time-(i-x)/cas[grid[i][y]].v)%cas[grid[i][y]].t == )
return false;
if(grid[i][y])break;
}
return true;
} bool bfs()
{
node tmp;
queue<node> q;
memset(vis, , sizeof(vis));
vis[][][] = ;
tmp.setNode(, , );
q.push(tmp);
int x, y, nx, ny, step;
if(grid[n][m])return false;
while(!q.empty())
{
x = q.front().x;
y = q.front().y;
step = q.front().step;
if(step>d)return false;
q.pop();
for(int i = ; i < ; i++)
{
nx = x+dx[i];
ny = y+dy[i];
if(nx>=&&nx<=n&&ny>=&&ny<=m&&!grid[nx][ny]&&!vis[nx][ny][step+]&&judge(nx, ny, step+)&&step+<=d)
{
if(nx==n&&ny==m){
ans = step+;
return true;
}
vis[nx][ny][step+] = ;
tmp.setNode(nx, ny, step+);
q.push(tmp);
}
}
}
return false;
} int main()
{
while(scanf("%d%d%d%d", &n, &m, &k, &d)!=EOF)
{
int x, y;
char ch[];
memset(grid, , sizeof(grid));
for(int i = ; i <= k; i++)
{
scanf("%s%d%d%d%d", ch, &cas[i].t, &cas[i].v, &x, &y);
cas[i].dir = ch[];
grid[x][y] = i;
}
if(bfs())printf("%d\n", ans);
else printf("Bad luck!\n");
} return ;
}
HDU3533(KB2-D)的更多相关文章
- HDU3533(Escape)
不愧是kuangbin的搜索进阶,这题没灵感写起来好心酸 思路是预处理所有炮台射出的子弹,以此构造一个三维图(其中一维是时间) 预处理过程就相当于在图中增加了很多不可到达的墙,然后就是一个简单的bfs ...
- HDU3533 Escape —— BFS / A*算法 + 预处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others) ...
- HDU3533 Escape
题目: The students of the HEU are maneuvering for their military training. The red army and the blue a ...
- [Spring]01_环境配置
)在资源库界面点击Artifacts标签,然后点击libs-release-local,展开后依次点击org -> springframework -> spring.
- STM32库函数编程、Keli/MDK、stm32f103zet6
catalogue . Cortex-M3地址空间 . 基于标准外设库的软件开发 . 基于固件库实现串口输出(发送)程序 . 红外接收实验 . 深入分析流水灯例程 . GPIO再举例之按键实验 . 串 ...
- RFID-RC522、FM1702SL、M1卡初探
catalogue . 引言 . RC522芯片(读卡器)简介 . FM1702SL芯片(读卡器)简介 . RFID M1卡简介 . 读取ID/序列号(arduino uno.MFRC522芯片 Ba ...
- CSS布局(二)
本节内容:position.float.clear.浮动布局例子.百分比宽度 position CSS中的position属性设置元素的位置.属性值:static.relative.fixed.abs ...
- percona-toolkit 之 【pt-summary】、【pt-mysql-summary】、【pt-config-diff】、【pt-variable-advisor】说明
摘要: 通过下面的这些命令在接触到新的数据库服务器的时候能更好更快的了解服务器和数据库的状况. 1:pt-summary:查看系统摘要报告 执行: pt-summary 打印出来的信息包括:CPU.内 ...
- Android -- ImageSwitch和Gallery 混合使用
1. 实现效果
随机推荐
- “借刀杀人”之CSRF拿下盗图狗后台
最近我一个做贸易的朋友找到我,他发现自己拍摄的图片又被某个同行盗用了,而且是全站的图片基本都被盗用. 之前对方是引用他的图片链接,后面我给他做了防盗链解决了,现在对方是先下载图片,然后自己上传到服务器 ...
- 怎样使用Navicat Premium导出导入mysql数据库
首先,在Navicat Premium中连接要导出数据库的mysql数据库. 2 1.填写好连接数据库的信息后就可以连接到需要导出的数据库了. 3 打开要导出的数据库. 4 将数据库的结构和数据导出为 ...
- MySQL DeadLock故障排查过程
[作者] 刘博:携程技术保障中心数据库高级经理,主要关注Sql server和Mysql的运维和故障处理. [环境] 版本号:5.6.21 隔离级别:REPEATABLE READ [问题描述] 接到 ...
- 2 new出的对象 prototype与__proto__
对象没有原型对象,函数才有 new出的对象,this的会重新创建,二prototype并不会重新创建,而是追溯原型链的方式进行继承 var Book=function(id,bookname,pric ...
- (转)MySQL详解--锁
原文:http://blog.csdn.net/xifeijian/article/details/20313977 锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的计算资源( ...
- nginx+jwplayer配置flv/MP4点播系统, 视频拖动支持
一 配置nginx 1. 下载 nginx 最新版 http://nginx.org/ 2. 安装依赖库, 以ubuntu为例 apt-get install libpcre3 libpcre3-de ...
- 【Java并发编程】:使用wait/notify/notifyAll实现线程间通信
在java中,可以通过配合调用Object对象的wait()方法和notify()方法或notifyAll()方法来实现线程间的通信.在线程中调用wait()方法,将阻塞等待其他线程的通知(其他线程调 ...
- 面试:http协议
转自:http://www.cnblogs.com/ranyonsue/p/5984001.html#undefined HTTP简介 HTTP协议是Hyper Text Transfer Proto ...
- Java 国际化
国际化英文单词为:Internationalization,又称I18N,I为因为单词的第一个字母,18为这个单词的长度,而N代表这个单词的最后一个字母.国际化又称本地化(Localization,L ...
- activemq的三种通信方式
一.安装与启动 1.下载安装activemq,下载地址:http://activemq.apache.org/download.html. 2.安装完成后,进入其所在目录的bin目录下面,根据系统位数 ...