首页 技术 正文
技术 2022年11月17日
0 收藏 851 点赞 2,304 浏览 4363 个字

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.

HDU3533(KB2-D)

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

2010 ACM-ICPC Multi-University Training Contest(10)——Host by HEU 明明是考虑到挡子弹的,判断的时候却没有写,浪费了好多时间。。。

 //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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,028
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857