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. 实现效果
随机推荐
- Golang channel 的基本使用方法
package main import ( "fmt" "learner/Add" "time" ) //a. 普通类型,普通变量保存的就是 ...
- JavaScript基础流程控制(3)
day51 参考:https://www.cnblogs.com/liwenzhou/p/8004649.html for循环 while循环 三元运算 a>b条件成立,选a,不成立选b
- JDK源码学习之 java.util.concurrent.automic包
一.概述 Java从JDK1.5开始提供了java.util.concurrent.atomic包,方便程序员在多线程环境下无锁的进行原子操作.原子变量的底层使用了处理器提供的原子指令,但是不同的CP ...
- 表格(table)
<table border="1"; align="center" cellspacing="0"> <tr> &l ...
- 使用git工具删除github上的文件或者文件夹
解决 使用git工具删除github上的文件或者文件夹 当我们需要从github上删除一些我们不需要的文件或者文件夹时,如果通过github来操作的话,将会很麻烦,因为github只允许删除一个仓库, ...
- MATLAB基础操作笔记
A( i , : ) 表示 A矩阵的第 i 行所有元素 A( : , j ) 表示 A矩阵的第 j 列所有元素 A( : , : ) 表示 A矩阵的 所有元素 定义函数时,函数中有嵌套函数需要在结束时 ...
- 【洛谷p3994】Highway 二分+斜率优化DP
题目大意:给你一颗$n$个点的有根树,相邻两个点之间有距离,我们可以从$x$乘车到$x$的祖先,费用为$dis\times P[x]+Q[x]$,问你除根以外每个点到根的最小花费. 数据范围:$n≤1 ...
- java 算法 - 冒泡排序
冒泡排序: 冒泡排序是专门针对已有的一部分已经排序的数据进行排序的一种排序算法.假如你的数据中只有两个数据输乱序的,那么冒泡排序就是最快的.这种算法的核心思想就是扫描数据清单,找到乱序中相邻的两个数据 ...
- Chapter 3 Phenomenon——17
Dr. Cullen raised his eyebrows. "Do you want to stay?" Cullen医生抬起了他的眉毛“你想待在这吗?” "No, ...
- vue-resource使用笔记
基本语法 //基于全局Vue对象使用http Vue.http.get('/someUrl', [options]).then(successCallback, errorCallback); Vue ...