记录编号 358373 评测结果 AAAAAAAAAA
题目名称 [UVa 11722] 和朋友会面 最终得分 100
用户昵称 Gravatarliu_runda 是否通过 通过
代码语言 C++ 运行时间 0.019 s
提交时间 2016-12-16 07:23:02 内存使用 0.29 MiB
显示代码纯文本
#include<cstdio>
const double eps=1e-8;
int a1,a2,b1,b2,w;
double f1(double x){
  if(x+w<=b1)return b2-b1;
  return (x+w<=b2&&x+w>=b1)?(b2-(x+w)):0;
}
double f2(double x){
  if(x-w<=b1)return b2-b1;
  return (x-w<=b2&&x-w>=b1)?(b2-(x-w)):0;
}
bool equal(double x,double y){
  return x-y<eps&&x-y>-eps;
}
double simpson(double l,double r,double f(double x)){
  double fl=f(l),fr=f(r);

  // printf("simpson%f %f %f %f\n",l,r,fl,fr);getchar();
  if(fl==0&&fr!=0&&r-l<eps)return 0;
  if(fr==0&&fl!=0&&r-l<eps)return 0;
  if(equal(fl-fr,r-l)||equal(fl-fr,l-r))return (fl+fr)*(r-l)/2.0;
  if(fl==fr)return fl*(r-l);
  return simpson(l,(l+r)/2.0,f)+simpson((l+r)/2.0,r,f);
}
double area1(){//area that is left up of y=x+w
  return simpson(a1,a2,f1);
}
double area2(){//area that is left up of y=x-w
  return simpson(a1,a2,f2);
}
int main(){
  freopen("joining.in","r",stdin);
  freopen("joining.out","w",stdout);
  int tests,cases=0;scanf("%d",&tests);
  while(tests--){
    scanf("%d%d%d%d%d",&a1,&a2,&b1,&b2,&w);
    ++cases;
    // printf("%.8f %.8f\n",area2(),area1());
    printf("Case #%d: %.8f\n",cases,(area2()-area1())/double(a2-a1)/double(b2-b1));
  }
  fclose(stdin);fclose(stdout);
  return 0;
}
/*378 1035 488 1063 12*/