HDU 4932 Miaomiao ' s Geometry

Source: Internet
Author: User

BC A question to do when you want to go to the game and didn't think of any example of the result is a floating point value so the output I used the most upright. 000 now, think about it.

Test instructions: Give you a lot of points on the line now requires the same length of line to cover all the points on this side there are two requirements that these points can only be covered by the two endpoints of the segment 22 segments cannot intersect (remove the endpoint) ask the maximum number of line segments that satisfy the condition

Problem-solving ideas: first to order all the points from small to large and then record the difference between the two points and the difference between the half and then just go to fill to see if the condition is satisfied to find the maximum value my side is directly using the set to exclude all duplicate values and from large to small to determine the satisfaction of the direct break


#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <set> #

Include<vector> #include <algorithm> using namespace std;
#define EPS 1e-8 set<double> s;
Double num[60];

int n;
    BOOL Judge (double val) {bool last = false;
        for (int i = 1;i < n-1;i++) {if (!last && num[i]-num[i-1] >= val) last = false;
        else if (last && fabs (num[i-1] + val-num[i]) = = 0) last = false;
        else if (last && num[i]-num[i-1] – 2*val >= 0) last = false;
        else if (num[i + 1]-num[i] >= val) last = true;
    else return false;
} return true;
    } int main () {int T;
    scanf ("%d", &t);
        while (t--) {scanf ("%d", &n);
        for (int i = 0;i < n;i++) scanf ("%lf", &num[i]);
        Sort (num,num + N);
        S.clear ();
            for (int i = 1;i < n;i++) {S.insert (Num[i]-num[i-1]); S.insert ((Num[i]-NUM[I-1])/2.0);
        } double ans = 0.000;
        Set<double>::iterator it;
		for (it = s.end (); It! = S.begin (); it--) {if (judge (*it)) {ans = *it;
            Break
    }} printf ("%0.3lf\n", ans);
} return 0; }






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.