Hdu 4932 Miaomiao & amp; #39; s Geometry (violent)

Source: Internet
Author: User

Hdu 4932 Miaomiao & #39; s Geometry (violent)

Link: hdu 4932 Miaomiao's Geometry

There are several points on the x coordinate. Now we need to overwrite these points with several lines of equal length. If a point is covered by a line segment, it must be at the left or right endpoint of the line, and the positions of each line segment cannot overlap, so the maximum length is obtained.

Solution: There are pitfalls in this question. During the competition, the o (n) algorithm looks for the shortest distance between two points. However, this does not work at the beginning, for example,-1 0 10 12 18 20. In this case, the minimum maintenance time should be 12 ~ 18. The length is 6. This line segment can cover 12 and 18 points, and then-1 and 20 are at both ends. Therefore, there are only two points: 0 and 10. The length between 0 and 10 is 10 and greater than 6. Therefore, the two ends overlap.
After the game, enumerate the length between two points and half of the length to determine whether it is feasible and maintain the maximum value.

#include 
  
   #include 
   
    #include 
    
     #include using namespace std;const int maxn = 100;int n;double arr[maxn];bool judge (double w) {    double tmp = arr[0];    for (int i = 1; i < n; i++) {        if (fabs(arr[i] - tmp) < 1e-9 || arr[i] - tmp > w || fabs(arr[i] - tmp - w) < 1e-9)            tmp = arr[i];        else if (arr[i] < tmp)            return false;        else            tmp = arr[i] + w;    }    return true;}int main () {    int cas;    scanf("%d", &cas);    while (cas--) {        scanf("%d", &n);        for (int i = 0; i < n; i++)            scanf("%lf", &arr[i]);        sort(arr, arr + n);        double ans = 0;        for (int i = 1; i < n; i++) {            if (judge (arr[i] - arr[i-1]))                ans = max(ans, arr[i] - arr[i-1]);            else if (judge((arr[i] - arr[i-1]) / 2))                ans = max(ans, (arr[i] - arr[i-1]) / 2);        }        printf("%.3lf\n", (double)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.