标签:
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <queue> #include <stack> #include <bitset> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1|1 #define mem1(a) memset(a, -1, sizeof(a)) #define mem2(a) memset(a, 0x3f, sizeof(a)) #define rep(i, n, a) for(int i = a; i<n; i++) #define fi first #define se second typedef pair<int, int> pll; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e9+7; const int inf = 1061109567; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; double xa, xb, xc, xd, ya, yb, yc, yd, p, q, r; double dis(double x1, double y1, double x2, double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } double ternary(double x, double y) { double lx = xc, ly = yc, rx = xd, ry = yd; while(fabs(rx-lx)>eps || fabs(ry-ly)>eps) { double x1 = lx+(rx-lx)/3, x2 = lx+(rx-lx)/3*2; double y1 = ly+(ry-ly)/3, y2 = ly+(ry-ly)/3*2; double tmp1 = dis(x, y, x1, y1)/r+dis(x1, y1, xd, yd)/q+dis(x, y, xa, ya)/p; double tmp2 = dis(x, y, x2, y2)/r+dis(x2, y2, xd, yd)/q+dis(x, y, xa, ya)/p; if(tmp1>tmp2) { lx = x1, ly = y1; } else { rx = x2, ry = y2; } } return dis(x, y, lx, ly)/r+dis(lx, ly, xd, yd)/q+dis(x, y, xa, ya)/p; } double solve() { double lx = xa, rx = xb, ly = ya, ry = yb; while(fabs(rx-lx)>eps || fabs(ry-ly)>eps) { double x1 = lx+(rx-lx)/3, x2 = lx+(rx-lx)/3*2; double y1 = ly+(ry-ly)/3, y2 = ly+(ry-ly)/3*2; double tmp1 = ternary(x1, y1), tmp2 = ternary(x2, y2); if(tmp1>tmp2) { lx = x1, ly = y1; } else { rx = x2, ry = y2; } } return ternary(lx, ly); } int main() { cin>>xa>>ya>>xb>>yb>>xc>>yc>>xd>>yd>>p>>q>>r; double ans = solve(); printf("%.2f\n", ans); return 0; }
标签:
原文地址:http://www.cnblogs.com/yohaha/p/5225319.html