BZOJ1857: [Scoi2010]傳送帶(三分套三分)

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 2005  Solved: 1091
[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


Sample Output

136.60

HINT

對於100%的數據,1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10php

Source

Day2spa

 
很顯然最優的路線必定是從A走到AB上的一點走到CD上的一點再走到D
而後三分套三分就能夠了
 
 
#include<cstdio> #include<cmath> #include<algorithm>
#define eps 1e-3
using namespace std; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0',c = getchar(); return x * f; } int Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, P, Q, R; double dis(double x, double y, double x2, double y2) { return sqrt((x2 - x) * (x2 -x) + (y2 - y) * (y2 - y)); } double check2(double x,double y,double x2,double y2) { return dis(Ax, Ay, x, y) / P + dis(x, y, x2, y2) / R + dis(x2, y2, Dx, Dy) / Q; } double check(double x, double y) { double lx = Cx, ly = Cy, rx = Dx, ry = Dy, a, b; while(abs(rx - lx) > eps || abs(ry - ly) > eps) { double wx1 = (lx * 2 + rx) / 3, wy1 = (ly * 2 + ry) / 3, wx2 = (lx + rx * 2) / 3, wy2 = (ly + ry * 2) / 3; a = check2(x, y, wx1, wy1); b = check2(x, y, wx2, wy2); if(a > b) lx = wx1, ly = wy1; else rx = wx2, ry = wy2; } return check2(x, y, lx, ly); } int main() { #ifdef WIN32 freopen("a.in","r",stdin); #endif Ax = read(), Ay = read(), Bx = read(), By = read(), Cx = read(), Cy = read(), Dx = read(), Dy = read(), P = read(), Q = read(), R = read(); double lx = Ax, ly = Ay, rx = Bx, ry = By; while(abs(rx - lx) > eps || abs(ry - ly) > eps) { double wx1 = (lx * 2 + rx) / 3, wy1 = (ly * 2 + ry) / 3, wx2 = (lx + rx * 2) / 3, wy2 = (ly + ry * 2) / 3; if(check(wx1, wy1) > check(wx2, wy2)) lx = wx1, ly = wy1; else rx = wx2, ry = wy2; } printf("%.2lf", check(lx, ly)); return 0; }
相關文章
相關標籤/搜索