HDU 1001 (TLE code)★To be modified★

Source: Internet
Author: User
1 # include <stdio. h> 2 # include <math. h> 3 struct node {4 double X, Y; 5} Point [100000]; 6 struct node nod; 7 int n = 0, I = 0; 8 int sort (void) {// select sorting: 9 Int J, K; 10 for (I = 0; I <n; I ++) {11 nod. X = point [I]. x; 12 nod. y = point [I]. y; 13 K = I; 14 for (j = I + 1; j <n; j ++) {15 if (nod. x> point [J]. x) {16 nod. X = point [J]. x; 17 nod. y = point [J]. y; 18 k = J; 19} 20} 21 if (K! = I) {22 point [K]. X = point [I]. x; 23 point [K]. y = point [I]. y; 24 point [I]. X = nod. x; 25 point [I]. y = nod. y; 26} 27} 28 return 0; 29} 30 double distance (INT num1, int num2) {// calculate the 31 return SQRT (point [num2]. x-point [num1]. x) * (point [num2]. x-point [num1]. x) + (point [num2]. y-point [num1]. y) * (point [num2]. y-point [num1]. y); 32} 33 double min (double left, double right) {34 return left <= right? Left: Right; 35} 36 double close (int s, int e) {// locate the closest two segments, which are 37 double closest = 0.0, Left = 0.0, Right = 0.0; 38 int mid = 0, I, J, K, T; 39 int A [50000] = {0}, B [50000] = {0 }; 40 mid = (S + E)> 1; 41 if (S + 1 = e) 42 return distance (S, e); 43 If (S = E) 44 return 1.7976931348623158e + 308; 45 46 left = close (S, mid); 47 right = close (Mid + 1, e); 48 closest = min (left, right ); 49 50 for (I = 1, j = 0; I <mid; I ++) {// record all the subscript of the mid axis with the left distance less than closest in A51 if (point [Mi D]. x-point [Mid-I]. x) <= closest) 52 A [J ++] = mid-I; 53 else54 break; 55} 56 for (I = 1, K = 0; I <(n-mid-1); I ++) {57 if (point [Mid + I]. x-point [Mid]. x) <= closest) 58 B [k ++] = Mid + I; 59 else60 break; 61} 62 // locate the minimum distance 63 for (I = 0; I <j; I ++) {64 for (t = 0; T <K; t ++) {65 if (closest> distance (A [I], B [T]) {66 closest = distance (A [I], B [T]); 67} 68} 69} 70 return closest; 71} 72 int main () 73 {74 int S = 0, E = 0; 75 double tar = 0.0; 76 whil E (scanf ("% d", & N )! = EOF & n! = 0) {77 for (I = 0; I <n; I ++) {// enter all coordinate points 78 scanf ("% lf ", & point [I]. x, & point [I]. y); 79} 80 s = 0; 81 e = n-1; 82 sort (); // sort 83 tar = close (S, e ); // find the shortest path 84 If (tar <0.000001) 85 printf ("0.00 \ n"); 86 else {87 tar = tar/2; 88 printf ("%. 2f \ n ", TAR); 89} 90} 91 return 0; 92}

The specific ideas and practices refer to the http://blog.csdn.net/sun1956/article/details/8294048 of this Article

The above Code is based on the explanation in this article, which is different from the original one.

After HDU on the Po, the problem persists. It has been modified for five hours and is still in the TLE. The three data pieces of the question are calculated.

If you have trouble, please help me find out what the problem is. I can't waste any time on this question. I may check the bug later. Haha

 

HDU 1001 (TLE code)★To be modified★

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.