首页 技术 正文
技术 2022年11月15日
0 收藏 746 点赞 3,424 浏览 1480 个字

【BZOJ1857】[Scoi2010]传送带

Description

在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段。两条传送带分别为线段AB和线段CD。lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R。现在lxhgww想从A点走到D点,他想知道最少需要走多长时间

Input

输入数据第一行是4个整数,表示A和B的坐标,分别为Ax,Ay,Bx,By 第二行是4个整数,表示C和D的坐标,分别为Cx,Cy,Dx,Dy 第三行是3个整数,分别是P,Q,R

Output

输出数据为一行,表示lxhgww从A点走到D点的最短时间,保留到小数点后2位

Sample Input

0 0 0 100
100 0 100 100
2 2 1

Sample Output

136.60

HINT

对于100%的数据,1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10

题解:最终路径一定是先在AB上走x米,然后直线走到CD上,再走y米。那么如果x确定了,最终答案显然是一个关于y的单峰函数,可以直接三分(其实感觉可以O(1)算)。但是x的位置如何确定呢?x的位置也是一个单峰函数!证明不太会,网上有~

所以三分套三分即可。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
struct point
{
double x,y;
point() {}
point(double a,double b) {x=a,y=b;}
point operator + (const point &a) const {return point(x+a.x,y+a.y);}
point operator * (const double &a) const {return point(x*a,y*a);}
}s1,t1,s2,t2;
double P,Q,R,ans;
inline double dis(point a,point b)
{
return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}
inline double calc(point a,point b)
{
double tmp=dis(s1,a)/P+dis(a,b)/R+dis(b,t2)/Q;
ans=min(ans,tmp);
return tmp;
}
double check(point S)
{
point l=s2,r=t2,m1,m2;
for(int i=1;i<=50;i++)
{
m1=(l*(2.0/3))+(r*(1.0/3)),m2=(l*(1.0/3))+(r*(2.0/3));
if(calc(S,m1)<calc(S,m2))r=m2;
elsel=m1;
}
return calc(S,l);
}
int main()
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&s1.x,&s1.y,&t1.x,&t1.y,&s2.x,&s2.y,&t2.x,&t2.y,&P,&Q,&R);
point l=s1,r=t1,m1,m2;
ans=1e10;
for(int i=1;i<=50;i++)
{
m1=(l*(2.0/3))+(r*(1.0/3)),m2=(l*(1.0/3))+(r*(2.0/3));
if(check(m1)<check(m2))r=m2;
elsel=m1;
}
printf("%.2lf",ans);
return 0;
}//0 0 100 0 100 100 0 100 2 2 1
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,411
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,184
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,904