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. jzoj2941

    我們可以暴力枚舉每一個人分幾個糖果,再暴力統計答案即可 每次遞歸下去可以從1-n號人,決定選多少個糖果再遞歸 #include<bits/stdc++.h> using namespace ...

  2. webservice gsoap 小记

    参考 http://www.cs.fsu.edu/~engelen/soap.html 1. web service client application > wsdl2h -s -o MyHe ...

  3. [Swift实际操作]七、常见概念-(11)路径URL的使用详解

    本文将为你演示网址对象(URL)的使用 首先导入需要使用的界面工具框架 import UIKit 接着初始化一个指定网址的网址对象 let url = URL(string: "https: ...

  4. linux系统上内网ip和和外网ip的关系

    1.不同服务之间的访问需要使用公网IP+端口才能访问 2.服务器上一般都是域名访问,服务器会把ip+端口映射成固定的域名,所以如果想访问服务器上其他应用,就必须的放开应用限制 问题,在服务器上放开对某 ...

  5. angular.js的依赖注入解析

    本教程使用AngularJS版本:1.5.3        angularjs GitHub: https://github.com/angular/angular.js/        Angula ...

  6. leetcode-914-卡牌分组

    题目描述: 给定一副牌,每张牌上都写着一个整数. 此时,你需要选定一个数字 X,使我们可以将整副牌按下述规则分成 1 组或更多组: 每组都有 X 张牌. 组内所有的牌上都写着相同的整数. 仅当你可选的 ...

  7. 课程一(Neural Networks and Deep Learning),第一周(Introduction to Deep Learning)—— 2、10个测验题

    1.What does the analogy “AI is the new electricity” refer to?  (B) A. Through the “smart grid”, AI i ...

  8. 剑指offer四十六之孩子们的游戏(圆圈中最后剩下的数,约瑟夫环问题)

    一.题目 每年六一儿童节,牛客都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此.HF作为牛客的资深元老,自然也准备了一些小游戏.其中,有个游戏是这样的:首先,让小朋友们围成一个大圈.然后,他随机指 ...

  9. 【Java并发编程】:多线程环境中安全使用集合API

    在集合API中,最初设计的Vector和Hashtable是多线程安全的.例如:对于Vector来说,用来添加和删除元素的方法是同步的.如果只有一个线程与Vector的实例交互,那么,要求获取和释放对 ...

  10. 【jQuery源码】select方法

    /** * select方法是Sizzle选择器包的核心方法之一,其主要完成下列任务: * 1.调用tokenize方法完成对选择器的解析 * 2.对于没有初始集合(即seed没有赋值)且是单一块选择 ...