[2016-03-05] [Uvalive] [4504] [Trick or Treat]

Source: Internet
Author: User
Tags cmath

[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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.