Escape HDU - 3533

问题:

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!

大意:

给你图的大小n*m,碉堡数目和最多可以利用的时间,然后是碉堡射击方向,射击频率,射击速度和位置。

要从0,0点,走到n,m点,途中不能射出的子弹击中,如果可以在规定时间内完成,输出最短时间,如果不能输出“Bad luck!”。

思路:

1:碉堡所在的位置不能走,所用时间不能超过规定时间,可以在原地不动(就是在原来的位置上时间+1,看看能不能躲过子弹)。

2:采用广搜,当走到某一点时,去暴力四个方向是否有碉堡和射击方向是否朝向这个位置,然后判断能否被击中。因为每走到一个位置所用的时间不一样算是不同的情况,所以可以采用三维数组把时间也标记一下。

3:每个碉堡只朝一个固定方向射击,子弹能被别的碉堡挡住。

4:子弹在飞行的过程中不会击中人,(1)当子弹的射速是v时,只有子弹离碉堡距离是v的倍数的位置才有可能击中人。(2)然后去判断射击频率,只有当人所用的时间是子弹频率倍数时也才有可能击中人。也就是以上两种情况都符合就会被击中。

代码就不贴出来了,毕竟也是看的大佬的。

猜你喜欢

转载自blog.csdn.net/lxxdong/article/details/81216884
今日推荐