第一次看到还有这种反派题
Speedy Escape
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 574 Accepted Submission(s): 188
Special Judge
Problem Description
![](https://i-blog.csdnimg.cn/blog_migrate/b66482d5b04587448cc4928c88d21b4a.png)
The Newton brothers are planning to rob a bank in the city of Alviso and want to figure out a way to escape the city's only police car. They know that their car is faster than the police car so if they could just reach one of the highways exiting the city they will be able to speed away from the police.
The police car has a maximum speed of 160 km/h. Luckily, the brothers know where the police car will start (it's parked at the police station). To be on the safe side they assume that the police car will start moving as soon as they leave the bank and start their car (this is when the alarm goes off).
The brothers want to find a fixed route that ensures that they are able to leave the city no matter what route the police car take and at what speed it drives. However, since the brothers are not very confident drivers they don't want to drive faster than necessary. Luckily they have recently invested in a new hi-tech in-car police escape system that you have constructed. This system will tell them what the minimal top speed needed to escape is (and probably other useful things like what route to take).
Let's turn the clock back a bit to the time when you were constructing the escape system and focused on finding the minimal required speed. Can you get it right?
You may treat all roads as infinitesimally narrow and both cars as point objects. If the brothers ever end up at the same point (on any road or intersection) at the same time as the police car they will be caught and by Murphy's law if there is any possibility of this happening it will happen. The two cars start simultaneously and can accelerate/decelerate instantaneously at any time to any speed below or equal to its maximum speed. They can also change roads at intersections or direction anywhere on a road instantaneously no matter what speed they are traveling at.
Input
The first line of the input consists of three integers
n,
m and
e, where 2 <=
n <= 100 describe the number of intersections, 1 <=
m <= 5000 describes the number of roads in the city and 1 <=
e <=
n describes the number of highway exits. Then follow
m lines, each consisting of three integers
a,
b,
l such that 1 <=
a <
b <=
n and 1 <=
l <= 100 describing a road of length
l hundred meters from intersection
a to intersection
b. Then follows a line of
e integers, each one a number in 1, ...,
n describing which intersections are connected to highway exits. Finally there is a line with two integers
b and
p (1 <=
b,
p <=
n and
b !=
p) describing the intersections where the brothers and the police cars start, respectively.
It will always be possible to travel from any intersection to any other intersection. Roads are only connected at intersection points (although they may cross using bridges or tunnels at others points). Roads can be used in both directions but there cannot be more than one road between two intersections.
It will always be possible to travel from any intersection to any other intersection. Roads are only connected at intersection points (although they may cross using bridges or tunnels at others points). Roads can be used in both directions but there cannot be more than one road between two intersections.
Output
The minimal speed in km/h required to escape or the word
IMPOSSIBLE if it is impossible. In the first case any answer with either absolute or relative error smaller than 10
-6 is acceptable.
Sample Input
3 2 1 1 2 7 2 3 8 1 3 2 3 2 1 1 2 7 2 3 8 1 2 3 4 4 2 1 4 1 1 3 4 3 4 10 2 3 30 1 2 3 4
Sample Output
IMPOSSIBLE 74.6666666667 137.142857143
Source
Recommend
Home | Top | Hangzhou Dianzi University Online Judge 3.0 Copyright © 2005-2017 HDU ACM Team. All Rights Reserved. Designer & Developer : Wang Rongtao LinLe GaoJie GanLu Total 0.000000(s) query 5, Server time : 2017-10-12 14:03:49, Gzip enabled | Administration |
但是有个东西是可以确定的,警察足够聪明,他跑向一个点肯定是最短路(但是你不知道他会去哪个点),所以咱就需要首先预处理出来警察都所有点的最短路;
然后我们再来考虑罪犯,罪犯能安全的到达一个点的前提条件是他能安全到达与这个点有连边的点,再从这些点过来,于是就有了一个dp方程,到一个点的最小速度等于min(max(上一个点的最小速度 ,( 以该速度到这个上一个点的最短距离 + 边长) / 警察到该点的时间));每次维护一个安全到某个点的最小速度和以该速度形式到该点的最短路程;(用迪杰斯特拉来搞定dp顺序);
代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define M 101
using namespace std;
int n , m;
double speed[M];
int p , q , set[M] , cnt;
int dis[M] , vis[M] , dp[M];
const int Inf = (1 << 31) - 1;
int ind[M] , nex[5010 * 2] , e[5010 * 2] , lon[5010 * 2] , tot;
void add(int a , int b , int c){
nex[++tot] = ind[a];
e[ind[a] = tot] = b;
lon[tot] = c;
}
void djstl(){
for(int i = 1 ; i <= n ; ++i)dis[i] = Inf , vis[i] = 0;
int amo = n;
dis[q] = 0;
while(amo--){
int v = 0 , min_ = Inf;
for(int i = 1 ; i <= n ; ++i)
if(!vis[i] && min_ > dis[i])
v = i , min_ = dis[i];
if(min_ == Inf)break;
vis[v] = 1;
for(int i = ind[v] ; i ; i = nex[i]){
int u = e[i];
if(!vis[u] && dis[u] > dis[v] + lon[i])
dis[u] = dis[v] + lon[i];
}
}
}
void djstl_ex(){
for(int i = 1 ; i <= n ; ++i)vis[i] = 0 , speed[i] = Inf , dp[i] = Inf;
int amo = n;
dp[p] = 0 , speed[p] = 0;
while(amo--){
int v = 0 ;
double min_ = Inf;
for(int i = 1 ; i <= n ; ++i)
if(!vis[i] && min_ > speed[i] && i != q)
min_ = speed[i] , v = i;
if(min_ == Inf)break;
vis[v] = 1;
for(int i = ind[v] ; i ; i = nex[i]){
int u = e[i];
double k = max(speed[v] , (dp[v] + lon[i]) * 1.0 / (dis[u]* 1.0 / 160.0));
if(!vis[u] && speed[u] > k && u != q)
speed[u] = k , dp[u] = dp[v] + lon[i];
}
}
}
int main(){
while(scanf("%d%d%d",&n,&m,&cnt) != EOF){
memset(ind , 0 , sizeof ind);
memset(nex , 0 , sizeof nex);
memset(lon , 0 , sizeof lon);
memset( e , 0 , sizeof e );
tot = 0;
double ans = Inf;
for(int i = 1; i <= m ; ++i){
int a , b , c;
scanf("%d%d%d",&a,&b,&c);
add(a , b , c);
add(b , a , c);
}
for(int i = 1 ; i <= cnt ; ++i)
scanf("%d",&set[i]);
scanf("%d%d",&p,&q);
djstl();
djstl_ex();
for(int i = 1 ; i <= cnt ; ++i)
ans = min(ans , speed[set[i]]);
if(ans == Inf)printf("IMPOSSIBLE\n");
else printf("%.8f\n",ans);
}
}
/*
3 2 1
1 2 7
2 3 8
1
3 2
3 2 1
1 2 7
2 3 8
1
2 3
4 4 2
1 4 1
1 3 4
3 4 10
2 3 30
1 2
3 4
*/
Home | Top | Hangzhou Dianzi University Online Judge 3.0 Copyright © 2005-2017 HDU ACM Team. All Rights Reserved. Designer & Developer : Wang Rongtao LinLe GaoJie GanLu Total 0.000000(s) query 5, Server time : 2017-10-12 14:03:49, Gzip enabled | Administration |