传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2328
题解传送门:http://www.cnblogs.com/Randolph87/p/3667963.html
Code:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+10;
const double eps=1e-7;
int T,n;
double vmax,a,b,f;
int dcmp(double x){
if(fabs(x)<eps)return 0;
return x>0?1:-1;
}
struct road{
double len,s,v;
bool operator<(const road &r)const{
return v<r.v;
}
}r[maxn];
int main(){
scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf%lf",&a,&b,&vmax,&f);
scanf("%d",&n);
for(int i=1;i<=n;i++){
double x,y;
scanf("%lf%lf",&x,&y);
r[i].s=y/x;
r[i].len=sqrt(x*x+y*y)/1000.0;
if(dcmp(r[i].s)==1)f-=b*r[i].s*r[i].len;
if(dcmp(r[i].s)==-1)r[i].v=-b*r[i].s/a;else r[i].v=0;
}if(dcmp(f)<0){
puts("IMPOSSIBLE");continue;
}
sort(r+1,r+1+n);
for(int i=1;i<=n;i++)
r[i].v=min(r[i].v,vmax);
r[n+1].v=vmax;
double sum=0;
int i;
for(i=1;i<=n;i++){
sum+=r[i].len;
if(dcmp(r[i].v-r[i+1].v)){
if(dcmp(f-(r[i+1].v-r[i].v)*sum*a)>=0){
f-=(r[i+1].v-r[i].v)*sum*a;
r[i].v=r[i+1].v;
}else{
r[i].v+=f/(sum*a);
break;
}
}
}
for(int j=i-1;j>=1;j--)
r[j].v=r[j+1].v;
if(dcmp(r[1].v)==0){
puts("IMPOSSIBLE");
continue;
}
double ans=0;
for(int i=1;i<=n;i++)
ans+=r[i].len/r[i].v;
printf("%.5lf\n",ans);
}
return 0;
}