看到大佬(star_xingchen_c01:45)写的,仍然有许多不明了的地方,分享转载给大家。
F. RC Kaboom Showtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
You know, it’s hard to conduct a show with lots of participants and spectators at the same place nowadays. Still, you are not giving up on your dream to make a car crash showcase! You decided to replace the real cars with remote controlled ones, call the event “Remote Control Kaboom Show” and stream everything online.For the preparation you arranged an arena — an infinite 2D-field. You also bought nn remote controlled cars and set them up on the arena. Unfortunately, the cars you bought can only go forward without turning left, right or around. So you additionally put the cars in the direction you want them to go.To be formal, for each car ii (1≤i≤n1≤i≤n) you chose its initial position (xi,yixi,yi) and a direction vector (dxi,dyidxi,dyi). Moreover, each car has a constant speed sisi units per second. So after car ii is launched, it stars moving from (xi,yixi,yi) in the direction (dxi,dyidxi,dyi) with constant speed sisi.The goal of the show is to create a car collision as fast as possible! You noted that launching every car at the beginning of the show often fails to produce any collisions at all. Thus, you plan to launch the ii-th car at some moment titi. You haven’t chosen titi, that’s yet to be decided. Note that it’s not necessary for titi to be integer and titi is allowed to be equal to tjtj for any i,ji,j.The show starts at time 00. The show ends when two cars ii and jj (i≠ji≠j) collide (i. e. come to the same coordinate at the same time). The duration of the show is the time between the start and the end.What’s the fastest crash you can arrange by choosing all titi? If it’s possible to arrange a crash then print the shortest possible duration of the show. Otherwise, report that it’s impossible.InputThe first line contains a single integer nn (1≤n≤250001≤n≤25000) — the number of cars.Each of the next nn lines contains five integers xixi, yiyi, dxidxi, dyidyi, sisi (−103≤xi,yi≤103−103≤xi,yi≤103; 1≤|dxi|≤1031≤|dxi|≤103; 1≤|dyi|≤1031≤|dyi|≤103; 1≤si≤1031≤si≤103) — the initial position of the ii-th car, its direction vector and its speed, respectively.It’s guaranteed that all cars start at distinct positions (i. e. (xi,yi)≠(xj,yj)(xi,yi)≠(xj,yj) for i≠ji≠j).OutputPrint the shortest possible duration of the show if it’s possible to arrange a crash by choosing all titi. Otherwise, print “No show 😦”.Your answer is considered correct if its absolute or relative error does not exceed 10−610−6.Formally, let your answer be aa, and the jury’s answer be bb. Your answer is accepted if and only if |a−b|max(1,|b|)≤10−6|a−b|max(1,|b|)≤10−6.
Examples
input
4
3 -1 -1 1 2
2 3 -3 -2 10
-4 2 1 -2 1
-2 -2 -1 2 4
output
0.585902082262898
inputCopy2
-1 1 -1 1 200
1 1 1 5 200
output
No show 😦
NoteHere is the picture for the first example:The fastest cars to crash are cars 22 and 44. Let’s launch car 22 at 00, car 44 at about 0.0967620.096762 and cars 11 and 33 at arbitrary time. That way cars 22 and 44 will crash into each other at about 0.5859020.585902. So here’s what it looks like at the moment of the collision:Here’s the picture for the second example:
#include<bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
#define mod 998244353
int n;
int x[25100],dx[25100],y[25100],dy[25100];
db v[25100];
db sol(int a,int b){
int kk=dx[b]*dy[a]-dy[b]*dx[a];
if(kk!=0){//相交
db r=0,rr=0;
r=x[a]*dy[a]+y[b]*dx[a]-y[a]*dx[a]-x[b]*dy[a];
rr=y[b]*dx[b]+x[a]*dy[b]-y[a]*dx[b]-x[b]*dy[b];
r/=(1.0*kk*v[b]);rr/=(1.0*kk*v[a]);
if(min(r,rr)<0) return -1;
else return max(r,rr);
}
else{//不相交
if((x[b]-x[a])*dy[a]!=(y[b]-y[a])*dx[a]) return -1; //平行
else{//重合
db aa=(x[a]*dx[a]+y[a]*dy[a]);
db bb=(x[b]*dx[a]+y[b]*dy[a]);
db v1=(dx[a]*dx[a]+dy[a]*dy[a])*v[a];
db v2=(dx[b]*dx[a]+dy[b]*dy[a])*v[b];
db t=-1;
if(v1*(bb-aa)>0&&v2*(aa-bb)>0) t=(bb-aa)/(v1-v2);
else if(v1*(bb-aa)>0) t=(bb-aa)/v1;
else if (v2*(aa-bb)>0)t=(aa-bb)/v2;
return t;
}
}
}
signed main(){
db ans=-1;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d%d%d%lf",&x[i],&y[i],&dx[i],&dy[i],&v[i]),v[i]/=sqrt(dx[i]*dx[i]+dy[i]*dy[i]);
for(int i=1;i<n;i++){
for(int j=i+1;j<=n;j++){
//cout<<"?"<<i<<" "<<j<<" "<<sol(i,j)<<endl;
db now=sol(i,j);
if(now>=0){
if(ans<0) ans=now;
else ans=min(ans,now);
}
}
}
if(ans<0) puts("No show :(");
else printf("%0.12lf\n",ans);
}