BZOJ 1857:[scoi2010] 传送带
来源:互联网 发布:2009年网络歌曲排行榜 编辑:程序博客网 时间:2024/05/24 03:59
[Scoi2010]传送带
Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 1450 Solved: 792
[Submit][Status][Discuss]
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
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
为什么用三分,其他博客有证明。。。
所以。。。看代码吧。。。
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#include<iomanip>using namespace std;struct data{double x,y;};data a,b,c,d;double v1,v2,v;inline double dis(data x,data y){return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));}inline data calculate(data x,data y,double t){data temp;temp.x=x.x+(y.x-x.x)*t;temp.y=x.y+(y.y-x.y)*t;return temp;}inline double workout(data x,data y){return dis(a,x)/v1+dis(d,y)/v2+dis(x,y)/v;}inline double solve(data k){double l=0.0,r=1.0;while(fabs(r-l)>1e-9){double t=(r-l)/3,lm=l+t,rm=r-t;data x=calculate(c,d,lm),y=calculate(c,d,rm);if(workout(k,x)<workout(k,y))r=rm;else l=lm;}return workout(k,calculate(c,d,(l+r)/2));}int main(){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",&v1,&v2,&v);double l=0.0,r=1.0,ans;while(fabs(r-l)>1e-9){double t=(r-l)/3,lm=l+t,rm=r-t;data x=calculate(a,b,lm),y=calculate(a,b,rm);double t1=solve(x),t2=solve(y);if(t1<t2)ans=t1,r=rm;else ans=t2,l=lm;}printf("%.2lf\n",ans);}
0 0
- BZOJ 1857: [Scoi2010]传送带
- BZOJ-1857-传送带-SCOI2010
- BZOJ 1857: [Scoi2010]传送带
- 【BZOJ 1857】 [Scoi2010]传送带
- BZOJ 1857 [Scoi2010]传送带
- BZOJ 1857:[scoi2010] 传送带
- BZOJ 1857 [Scoi2010]传送带 三分
- bzoj 1857 [Scoi2010]传送带
- bzoj 1857 [Scoi2010]传送带
- BZOJ 1857 [Scoi2010]传送带 三分套三分
- 【BZOJ 1857】【SCOI2010】传送带 【三分套三分】
- bzoj 1857: [Scoi2010]传送带 三分套三分
- 【BZOJ 1857】[Scoi2010]传送带 三分套三分
- Bzoj 1857: [Scoi2010]传送带(三分套三分)
- bzoj 1857 [SCOI2010]传送带【三分套三分】
- BZOJ 1857 [Scoi2010]传送带 三分套三分
- BZOJ P1857:[Scoi2010]传送带
- 1857: [Scoi2010]传送带
- jquery-ui中div拖动出现辅助线方便对齐
- OpenCV_(Using GrabCut extract the foreground object) 使用 GrabCut 算法提取前景物体
- Glide-渐进式加载初尝试
- Q86:镜面反射(Mirror Reflection)
- Android测试(一)
- BZOJ 1857:[scoi2010] 传送带
- 零基础学习JAVA—GPS数据处理
- 正则表达式 ?= 、?!
- android arr和jar的区别
- ServiceStack.Redis的使用以及Redis的数据类型
- crontab简易入门
- iOS------GCD的使用小结
- solr亿万级索引优化实践(三)
- opencv3.2.0编译没有X64解决方法