标签:stat desc pre ems int 最短时间 source pen ret
对于100%的数据,1<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10
#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; }
BZOJ1857: [Scoi2010]传送带(三分套三分)
标签:stat desc pre ems int 最短时间 source pen ret
原文地址:https://www.cnblogs.com/zwfymqz/p/8987507.html