[2016-03-05] [Uvalive] [4504] [Trick or Treat]
- Time: 2016-03-05-12:06:59 Saturday
- Title Number: uvalive 4504 B-trick or Treat
- Topic: Given the number of points on the axis, at each point there is a person, the x-axis on a point, so that everyone to the point set to spend the shortest amount of time, all the simultaneous departure,
- Input:
- Several sets of data, 0 end
- Each set of data
- N Vertex Count
- Next n rows, the coordinates of each vertex double type
- Output: Point coordinates, TIME required
- Analysis: It can be seen that the x-axis from the left to the most advantage, to the right, the time spent first lowered and then raised, then you can 3 points, to find the best answer
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; typedef Long long LL; #define The CLR (x , Y) memset ((×), (y),sizeof((x)))
const int maxn = 50000 +; int n; struct point{ double x, y; bool operator < (const Point a)const { return a.x > x; }}P[MAXN];double Calc (double x) { double rtn = 0;For (int i = 0; i < n; ++i) {RTN = max (RTN, sqrt (double(P[I].Y * p[i].y + (p[i].x-x) * (P[i].x-x ))); } return RTN;}double Solve (double MIN, double MAX) { Double left, right; Double mid = 0, Midmid = 0; double mid_area = 0, Midmid_area = 0; Left = MIN; right = MAX;For (int i = 0;i < 150;++i) {mid = (left + right)/2;Midmid = (mid + right)/2;Mid_area = Calc (mid);Midmid_area = Calc (midmid); if (Midmid_area-mid_area > EPS) right = Midmid; Else left = mid; } return midmid;}int Main () { while (~scanf ("%d", &n) && N) {For (int i = 0;i < n; ++i)scanf ("%lf%lf", &p[i].x,&p[i].y);sort (p,p+n); Double res = Solve (p[0].x,p[n-1].x);printf ("%.7lf%.7lf\n", Res,calc (res)); } return 0;}
|
From for notes (Wiz)
[2016-03-05] [Uvalive] [4504] [Trick or Treat]