Escape

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 541    Accepted Submission(s): 141

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!
 
 
 
 
 
非常纠结的一题,做了很久才做出来,题意非常不清楚,不推荐这题。
坑点:有碉堡的点不能走,人不会往回走,终点可能有碉堡。
先把所有可能被炮弹打到的点以及它被炮弹打到的时间标记出来,时间上限是初始能量值,因为超过了这个值就不能再走了,标记也就没意义。然后bfs搜的时候,用VIS[x][y][t]来判重,即当前点是否在第t秒以及走过了,我还加入了个曼哈顿距离来剪枝,如果当前点的剩余能量小于到终点的曼哈顿距离,那么就剪掉。
注意,更新x和y的时候,不必考虑向西和向北,因为终点是在东南方,刚开始我不确定这样对不对,但是去掉这两个点后依然能A,当然,也许是数据不够强,某个角落里还存在着一组诡异的数据,需要先绕回去几步,谁知道呢。
 
 #include <iostream>
#include <cstdio>
#include <queue>
using namespace std; const int SIZE = ;
const int UPDATE[][] = {{,},{,},{,}};
int N,M,K,E;
bool FIRE[SIZE][SIZE][];
bool VIS[SIZE][SIZE][];
bool CASTLE[SIZE][SIZE];
struct Node
{
int x,y,t,e;
bool check(void)
{
if(x < || x > N || y < || y > M || t > E || VIS[x][y][t] || CASTLE[x][y] ||
FIRE[x][y][t] || !e || N - x + M - y > e)
return false;
return true;
}
};
struct Cas
{
char ch;
int t,v,x,y;
}; void deal(char ch,int t,int v,int x,int y);
void bfs(void);
int main(void)
{
Cas temp[];
while(scanf("%d%d%d%d",&N,&M,&K,&E) != EOF)
{
fill(&FIRE[][][],&FIRE[SIZE - ][SIZE - ][],false);
fill(&VIS[][][],&VIS[SIZE - ][SIZE - ][],false);
fill(&CASTLE[][],&CASTLE[SIZE - ][SIZE - ],false); for(int i = ;i < K;i ++)
{
scanf(" %c%d%d%d%d",&temp[i].ch,&temp[i].t,&temp[i].v,&temp[i].x,&temp[i].y);
CASTLE[temp[i].x][temp[i].y] = true;
}
if(CASTLE[N][M])
{
puts("Bad luck!");
continue;
}
for(int i = ;i < K;i ++)
deal(temp[i].ch,temp[i].t,temp[i].v,temp[i].x,temp[i].y);
bfs();
} return ;
} void deal(char ch,int t,int v,int x,int y)
{
if(ch == 'W')
{
int stop = ;
for(int j = y - ;j >= ;j --)
if(CASTLE[x][j])
{
stop = j;
break;
}
for(int j = y - v,ini = ;j >= stop;j -= v,ini ++)
for(int k = ini;k <= E;k += t)
FIRE[x][j][k] = true; }
else if(ch == 'E')
{
int stop = M;
for(int j = y + ;j <= M;j ++)
if(CASTLE[x][j])
{
stop = j;
break;
} for(int j = y + v,ini = ;j <= stop;j += v,ini ++)
for(int k = ini;k <= E;k += t)
FIRE[x][j][k] = true;
}
else if(ch == 'N')
{
int stop = ;
for(int j = x - ;j >= ;j --)
if(CASTLE[j][y])
{
stop = j;
break;
}
for(int j = x - v,ini = ;j >= stop;j -= v,ini ++)
for(int k = ini;k <= E;k += t)
FIRE[j][y][k] = true;
}
else if(ch == 'S')
{
int stop = N;
for(int j = x + ;j <= N;j ++)
if(CASTLE[j][y])
{
stop = j;
break;
}
for(int j = x + v,ini = ;j <= stop;j += v,ini ++)
for(int k = ini;k <= E;k += t)
FIRE[j][y][k] = true;
}
} void bfs(void)
{
Node first;
first.x = first.y = first.t = ;
first.e = E;
queue<Node> que;
que.push(first);
VIS[][][] = true; while(!que.empty())
{
Node cur = que.front();
que.pop(); for(int i = ;i < ;i ++)
{
Node next = cur;
next.x += UPDATE[i][];
next.y += UPDATE[i][];
next.t ++;
next.e --;
if(!next.check())
continue;
if(next.x == N && next.y == M)
{
printf("%d\n",next.t);
return ;
}
VIS[next.x][next.y][next.t] = true;
que.push(next);
}
}
puts("Bad luck!");
}

HDU 3533 Escape (BFS + 预处理)的更多相关文章

  1. 【搜索】 HDU 3533 Escape BFS 预处理

    要从0,0 点 跑到m,n点  路上会有k个堡垒发射子弹.有子弹的地方不能走,子弹打到别的堡垒就会消失,或者一直飞出边界(人不能经过堡垒 能够上下左右或者站着不动 每步都须要消耗能量  一共同拥有en ...

  2. HDU 3533 Escape bfs 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=3533 一道普通的bfs,但是由于代码实现出了bug还是拖了很久甚至对拍了 需要注意的是: 1.人不能经过炮台 2 ...

  3. HDU 3533 Escape(bfs)

    Escape Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  4. HDU 3533 Escape BFS搜索

    题意:懒得说了 分析:开个no[100][100][1000]的bool类型的数组就行了,没啥可说的 #include <iostream> #include <cstdio> ...

  5. HDU 3533 Escape(大逃亡)

    HDU 3533 Escape(大逃亡) /K (Java/Others)   Problem Description - 题目描述 The students of the HEU are maneu ...

  6. HDU 3533 Escape(BFS+预处理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 题目大意:给你一张n* m的地图,人在起点在(0,0)要到达终点(n,m)有k(k<=10 ...

  7. POJ-1077 HDU 1043 HDU 3567 Eight (BFS预处理+康拓展开)

    思路: 这三个题是一个比一个令人纠结呀. POJ-1077 爆搜可以过,94ms,注意不能用map就是了. #include<iostream> #include<stack> ...

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

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

  9. HDU - 1430 魔板 (bfs预处理 + 康托)

    对于该题可以直接预处理初始状态[0, 1, 2, 3, 4, 5, 6, 7]所有可以到达的状态,保存到达的路径,直接打印答案即可. 关于此处的状态转换:假设有初始状态为2,3,4,5,0,6,7,1 ...

随机推荐

  1. JDBC学习笔记(9)——DBUtils的使用

    使用DBUtils提供的功能需要使用commons-dbutils-1.6.jar这个JAR包,在Apache官网可以下载到 使用DBUtils进行更新操 测试QueryRunner类的update方 ...

  2. PC问题-该虚拟机似乎正在使用中

    问题现象:运行VMware Workstation,选中一个虚拟机,运行.卡住了,再运行VMware Workstation时,选中一个虚拟机,提示“该虚拟机似乎正在使用中”. 问题原因:因为上次非正 ...

  3. TQ210裸机编程(4)——按键(中断法)

    S5PV210有4个向量中断控制器(VIC),每个向量中断控制器包含32个中断源. 当某个中断源产生中断时,CPU会自动的将VICxVECTADDRy(x=0,1,2,3,y=0-31)寄存器的值赋给 ...

  4. POJ 1860 Currency Exchange (SPFA松弛)

    题目链接:http://poj.org/problem?id=1860 题意是给你n种货币,下面m种交换的方式,拥有第s种货币V元.问你最后经过任意转换可不可能有升值.下面给你货币u和货币v,r1是u ...

  5. PHP 中运用 elasticsearch

    PHP扩展安装 1. 环境要求:PHP_VERSION >= 5.3.9,composer工具 2. 在E盘新建文件夹命名为elastic,,拷贝composer.phar到      E:/e ...

  6. CSS 背景图片的定位和缩放

    在 CSS 中,利用 background-image 属性我们可以指定元素的背景图片,例如: .example { background-image: url(image/some.png); ba ...

  7. HttpContext讲解

    http://www.cnblogs.com/scy251147/p/3549503.html http://www.360doc.com/content/14/0526/10/17655805_38 ...

  8. Spark 1.3.0 单机安装

    一.试验环境: CentOS6.6 最小化安装:主机名spark-test,IP:10.10.10.26 OpenStack虚拟云主机. 注:安装流程:进入linux->安装JDK->安装 ...

  9. 【VxWorks系列】任务间同步与通信之共享内存

    在开始之前先说明三个概念,任务间的同步,互斥,通信. 同步,是指一个任务等待某个条件发生,而另外一个任务引发这个条件后,等待的任务会被触发执行相应的处理.这就是一个任务与另一任务之间的同步控制. 互斥 ...

  10. 我的第一个javascript网页作业

    1: <html> 2: <title> 3:   4: </title> 5: <body> 6: <style type="text ...