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

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)的更多相关文章

  1. HDU3533(Escape)

    不愧是kuangbin的搜索进阶,这题没灵感写起来好心酸 思路是预处理所有炮台射出的子弹,以此构造一个三维图(其中一维是时间) 预处理过程就相当于在图中增加了很多不可到达的墙,然后就是一个简单的bfs ...

  2. HDU3533 Escape —— BFS / A*算法 + 预处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others)  ...

  3. HDU3533 Escape

    题目: The students of the HEU are maneuvering for their military training. The red army and the blue a ...

  4. [Spring]01_环境配置

    )在资源库界面点击Artifacts标签,然后点击libs-release-local,展开后依次点击org -> springframework -> spring.

  5. STM32库函数编程、Keli/MDK、stm32f103zet6

    catalogue . Cortex-M3地址空间 . 基于标准外设库的软件开发 . 基于固件库实现串口输出(发送)程序 . 红外接收实验 . 深入分析流水灯例程 . GPIO再举例之按键实验 . 串 ...

  6. RFID-RC522、FM1702SL、M1卡初探

    catalogue . 引言 . RC522芯片(读卡器)简介 . FM1702SL芯片(读卡器)简介 . RFID M1卡简介 . 读取ID/序列号(arduino uno.MFRC522芯片 Ba ...

  7. CSS布局(二)

    本节内容:position.float.clear.浮动布局例子.百分比宽度 position CSS中的position属性设置元素的位置.属性值:static.relative.fixed.abs ...

  8. percona-toolkit 之 【pt-summary】、【pt-mysql-summary】、【pt-config-diff】、【pt-variable-advisor】说明

    摘要: 通过下面的这些命令在接触到新的数据库服务器的时候能更好更快的了解服务器和数据库的状况. 1:pt-summary:查看系统摘要报告 执行: pt-summary 打印出来的信息包括:CPU.内 ...

  9. Android -- ImageSwitch和Gallery 混合使用

    1. 实现效果

随机推荐

  1. django项目 设置session 实现用户登入登出

    一.配置文件 settngs.py中 # 使用django认知系统的登录状态装饰器时,没有登录的话,跳往登录页面后路径是/acount/login 需要重新指定 LOGIN_URL = '/user/ ...

  2. hdu-5875

    题目大意: f(l,r)=a[l]   l==r f(l,r)=f(l,r-1)%a[r]  l<r 思路: 由此可以推出f(l,r)=a[l]%a[l+1]%a[l+2]%....%a[r] ...

  3. POJ 2828Buy Tickets(线段树的单点维护)

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 20462   Accepted: 10096 Des ...

  4. 一次对webshell的后门的查看

    本文作者i春秋作家——非主流 昨天晚上突发奇想的想去看看github上面tennc的webshell收集项目中的shell有没有漏洞,比如未授权啊啥的,结果找半天都没找到...但是机缘巧合下,居然给我 ...

  5. nginx 开启GZIP、域名指向index.html

    nginx 虽然默认开启了gzip压缩,但是有关压缩文件.压缩效率没有开启,在建设我的(个人博客)[www.fayinme.cn]中,直观的感受到gzip带来的访问速度提升的快感. 如何开启GZIP ...

  6. JMeter基础:请求参数Parameters 、Body Data的区别

    使用Jmeter测试时,很多人不知道请求参数Parameters .Body Data的区别和用途,这里简单介绍下 先了解一个接口的基本概念 在客户机和服务器之间进行请求-响应时,HTTP协议中包括G ...

  7. ReentrantLock获取到非公平锁的源码

    /** * Performs lock. Try immediate barge, backing up to normal * acquire on failure. */ final void l ...

  8. css实现栏目两边斜线的效果

    实现效果: 具体实现代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  9. 理解JavaScript的数值型数据类型

    分享一些在JavaScript中遇到的一些实用的技巧. 理解JavaScript的数值型数据类型 JavaScript的数值型数据类型只有一种:number.即不管是整数还是浮点数,JavaScrip ...

  10. manifest.xml

    main action 和 laucher的categoty If either the MAIN action or LAUNCHER category are not declared for o ...