三分——Line belt
来源:互联网 发布:i started a joke 知乎 编辑:程序博客网 时间:2024/06/03 16:02
How long must he take to travel from A to D?
For each case, there are three lines.
The first line, four integers, the coordinates of A and B: Ax Ay Bx By.
The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.
The third line, three integers, P Q R.
0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10
10 0 0 100100 0 100 1002 2 1
136.60
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps=1e-8;
struct Point
{
double x,y;
}a,b,c,d,bb,dd;
double ab,cd,p,q,r;
double dis(Point u,Point v)
{
return sqrt(eps+(u.x-v.x)*(u.x-v.x)+(u.y-v.y)*(u.y-v.y));
}
double work(double t)
{
dd.x=d.x+(c.x-d.x)/cd*t*q;
dd.y=d.y+(c.y-d.y)/cd*t*q;
return t+dis(bb,dd)/r;
}
double solve(double t)
{
bb.x=a.x+(b.x-a.x)/ab*t*p;
bb.y=a.y+(b.y-a.y)/ab*t*p;
double l=0,h=cd/q,mid1,mid2;
while(h-l>eps)
{
mid1=(l*2+h)/3;
mid2=(h*2+l)/3;
if(work(mid1)<work(mid2))
h=mid2;
else
l=mid1;
}
return t+work(l);
}
int main()
{
int t;
cin>>t;
while(t--)
{
scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
scanf("%lf%lf%lf%lf",&c.x,&c.y,&d.x,&d.y);
scanf("%lf%lf%lf",&p,&q,&r);
ab=dis(a,b);
cd=dis(c,d);
double l=0,h=ab/p,mid1,mid2;
while(h-l>eps)
{
mid1=(l*2+h)/3;
mid2=(h*2+l)/3;
if(solve(mid1)<solve(mid2))
h=mid2;
else
l=mid1;
}
printf("%.2f\n",solve(mid1));
}
return 0;
}
这个是正确代码,但是如果dis哪里不加eps就是wa,我也是懵啊。哎西吧!
- 三分——Line belt
- Line belt 三分嵌套
- HDU 3400 Line belt 三分
- HDU 3400 Line belt 三分
- Line belt+hdu+三分搜索
- HDU3400 Line belt (几何+三分)
- HDU 3400 Line belt(三分)
- hud-3400-Line belt(三分)
- hdu3400 Line belt 【三分搜索】
- hdu 3400 Line belt 三分
- (三分 两次)Line belt -- HDOJ
- 三分搜索--hdu3400 Line belt
- Line belt (三分查找)
- HDU 3400 Line belt 三分
- 三分套三分 --- HDU 3400 Line belt
- hdu 3400 Line belt 双三分
- hdu 3400 Line belt【三分嵌套】
- hdu 3400 Line belt(三分)
- ios开发之字符串初始化(一)
- Unity 3D 资源的加载与释放
- Gym
- tomcat+nginx+redis实现均衡负载、session共享(二)
- 输入一个字符串,将其中的缩写形式展开,
- 三分——Line belt
- Head First设计模式学习笔记-------(13)代理模式
- hdu 2082 找单词 (母函数)
- HTTP协议头详解
- 颜色六位码和八位码表示
- Python学习笔记二---控制流
- Mybatis基本环境搭建
- SMS Server Tools 3
- jQuery基础二