标签:rip algorithm ica efi gcc bsp 最大 namespace ble
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2122 Accepted Submission(s): 884
#pragma GCC diagnostic error "-std=c++11" //#include <bits/stdc++.h> #define _ ios_base::sync_with_stdio(0);cin.tie(0); #include<iostream> #include<algorithm> #include<cstdio> using namespace std; const double eps = 1e-8; const int N= 300 + 5; struct point{ double x, y, vx, vy; void read(){ cin >> x >> y >> vx >> vy; } }p[N]; int n; double dist_points(point p1, point p2, double t){ double x = (p1.x + t * p1.vx) - (p2.x + t * p2.vx); double y = (p1.y + t * p1.vy) - (p2.y + t * p2.vy); return sqrt(x * x + y * y); } double cal(double x){ double Max = 0; for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) Max = max(Max, dist_points(p[i], p[j], x)); return Max; } double ternary_search(double L, double R){ if(L > R) swap(L, R); while(R - L > eps){ double mid1, mid2; mid1 = (L + R) / 2; mid2 = (mid1 + R) / 2; if(cal(mid1) <= cal(mid2)) R = mid2; else L = mid1; } return (L + R) / 2; } int main(){ _ int T, Cas = 0; cin >> T; while(T --){ cin >> n; for(int i = 0; i < n; i++) p[i].read(); double x = ternary_search(0, 1e8); printf("Case #%d: %.2f %.2f\n", ++Cas, x, cal(x)); } }
HDU-4717 The Moving Points(凸函数求极值)
标签:rip algorithm ica efi gcc bsp 最大 namespace ble
原文地址:http://www.cnblogs.com/Pretty9/p/7428188.html