[省选前题目整理][BZOJ 1857][SCOI 2010]传送带(三分套三分)
2015-04-10 19:44
399 查看
题目链接
http://www.lydsy.com/JudgeOnline/problem.php?id=1857思路
/article/8152236.html代码
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #include <cmath> #define EPS 1e-4 using namespace std; double P,Q,R,ax,ay,bx,by,cx,cy,dx,dy; inline double dist(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } inline double calc(double sx,double sy) //在(sx,sy)处离开传送带AB { double lowerBoundx=cx,upperBoundx=dx; double lowerBoundy=cy,upperBoundy=dy; while(fabs(upperBoundx-lowerBoundx)>EPS||fabs(upperBoundy-lowerBoundy)>EPS) { double midx1=lowerBoundx+(upperBoundx-lowerBoundx)/3,midx2=upperBoundx-(upperBoundx-lowerBoundx)/3; double midy1=lowerBoundy+(upperBoundy-lowerBoundy)/3,midy2=upperBoundy-(upperBoundy-lowerBoundy)/3; double f1=dist(ax,ay,sx,sy)/P+dist(sx,sy,midx1,midy1)/R+dist(midx1,midy1,dx,dy)/Q; double f2=dist(ax,ay,sx,sy)/P+dist(sx,sy,midx2,midy2)/R+dist(midx2,midy2,dx,dy)/Q; if(f1<f2) upperBoundx=midx2,upperBoundy=midy2; else lowerBoundx=midx1,lowerBoundy=midy1; } return dist(ax,ay,sx,sy)/P+dist(sx,sy,lowerBoundx,lowerBoundy)/R+dist(lowerBoundx,lowerBoundy,dx,dy)/Q; } int main() { scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy,&P,&Q,&R); double lowerBoundx=ax,upperBoundx=bx; double lowerBoundy=ay,upperBoundy=by; while(fabs(upperBoundx-lowerBoundx)>EPS||fabs(upperBoundy-lowerBoundy)>EPS) { double midx1=lowerBoundx+(upperBoundx-lowerBoundx)/3,midx2=upperBoundx-(upperBoundx-lowerBoundx)/3; double midy1=lowerBoundy+(upperBoundy-lowerBoundy)/3,midy2=upperBoundy-(upperBoundy-lowerBoundy)/3; double f1=calc(midx1,midy1),f2=calc(midx2,midy2); if(f1<f2) upperBoundx=midx2,upperBoundy=midy2; else lowerBoundx=midx1,lowerBoundy=midy1; } printf("%.2lf",calc(lowerBoundx,lowerBoundy)); return 0; }
相关文章推荐
- bzoj1857 [Scoi2010]传送带 [三分套三分]
- 【BZOJ1857】[Scoi2010]传送带 三分套三分
- 【BZOJ 1857】[Scoi2010]传送带 三分套三分
- bzoj 1857 [SCOI2010]传送带【三分套三分】
- BZOJ 1857 [Scoi2010]传送带 三分套三分
- Bzoj 1857: [Scoi2010]传送带(三分套三分)
- [BZOJ 1857][SCOI 2010]传送带(三分套三分)
- [BZOJ1857][Scoi2010]传送带(三分套三分+计算几何)
- 【BZOJ 1857】【SCOI2010】传送带 【三分套三分】
- bzoj1857: [Scoi2010]传送带(三分套三分)
- bzoj 1857: [Scoi2010]传送带 三分套三分
- BZOJ 1857 SCOI 2010 传送带 三分套三分
- 【模版】bzoj1857[Scoi2010]传送带 三分套三分
- BZOJ1857 SCOI2010 传送带 三分套三分
- BZOJ 1857 [Scoi2010]传送带 三分套三分
- 【BZOJ1857】[Scoi2010]传送带【三分套三分】
- 【bzoj1857】[Scoi2010]传送带 三分套三分
- bzoj1857 [ SCOI2010 ] -- 三分套三分
- 【BZOJ1857】【SCOI2010】传送带 [三分]
- 1857: [Scoi2010]传送带 三分套三分