Hdu 4932 Miaomiao & amp; #39; s Geometry (brute force enumeration)

Source: Internet
Author: User

Hdu 4932 Miaomiao & #39; s Geometry (brute force enumeration)
Miaomiao's GeometryTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Problem DescriptionThere are N point on X-axis. Miaomiao wowould like to cover them ALL by using segments with same length.

There are 2 limits:

1. A point is convered if there is a segments T, the point is the left end or the right end of T.
2. The length of the intersection of any two segments equals zero.

For example, point 2 is convered by [2, 4] and not convered by [1, 3]. [1, 2] and [2, 3] are legal segments, [1, 2] and [3, 4] are legal segments, but [1, 3] and [2, 4] are not (the length of intersection doesn't equals zero), [1, 3] and [3, 4] are not (not the same length ).

Miaomiao wants to maximum the length of segements, please tell her the maximum length of segments.

For your information, the point can't coincidently at the same position.
InputThere are several test cases.
There is a number T (T <= 50) on the first line which shows the number of test cases.
For each test cases, there is a number N (3 <= N <= 50) on the first line.
On the second line, there are N integers Ai (-1e9 <= Ai <= 1e9) shows the position of each point.
OutputFor each test cases, output a real number shows the answser. Please output three digit after the decimal point.
Sample Input

331 2 331 2 441 9 100 10

Sample Output
1.0002.0008.000HintFor the first sample , a legal answer is [1,2] [2,3] so the length is 1.For the second sample , a legal answer is [-1,1] [2,4] so the answer is 2.For the thired sample , a legal answer is [-7,1] , [1,9] , [10,18] , [100,108] so the answer is 8. 
N points are given, and some long line segments are found to overwrite these points. These points can only be used as the endpoints of a line segment, and the intersection length of any two line segments cannot be greater than 0. returns the maximum length of a line segment that meets the conditions. Analysis: the final result is the length between two adjacent points, or half of the length between two adjacent points. Because there are up to 50 points and 100 lengths, you only need to enumerate these lengths and find the longest line segment that meets the conditions.
# Include
 
  
# Include
  
   
# Includeusing namespace std; int main () {double B [120], c [60]; int flag [60]; int n, I, j, T; scanf ("% d", & T); while (T --) {scanf ("% d", & n); for (I = 0; I <n; I ++) scanf ("% lf", & c [I]); sort (c, c + n); int m = 0; for (I = 1; I <n; I ++) {B [m ++] = c [I]-c [I-1]; B [m ++] = (c [I]-c [I-1])/2;} sort (B, B + m); double ans; for (I = m-1; I> = 0; I --) {memset (flag, 0, sizeof (flag); flag [0] = 1; double tmp = B [I]; for (j = 1; j <n-1; j ++) {if (c [j]-tmp <c [J-1] & c [j] + tmp> c [j + 1]) // break is unavailable to the left to the right; if (c [j]-tmp> = c [J-1]) {if (flag [J-1] = 2) // previous one to the right {if (c [j]-c [J-1] = tmp) flag [j] = 1; // two vertices act as the two endpoints of a line segment else if (c [j]-c [J-1]> = 2 * tmp) flag [j] = 1; // One to the left, one else To the right if (c [j] + tmp <= c [j + 1]) flag [j] = 2; // only the right else break can be reached ;} else flag [j] = 1;} else if (c [j] + tmp <= c [j + 1]) flag [j] = 2 ;} if (j = n-1) {ans = tmp; break ;}} printf ("%. 3lf \ n ", double (ans);} return 0 ;}
  
 


Related Article

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.