Whim, with two threads that seem to optimize some violence
For example, the last point of the plane to this topic, the point copy into 2 copies
One is sorted by X, one is sorted by Y.
Then double-threading violence, one processing x, one processing y
If the data uses X to decrement the card, then because of the double thread, it can't hold Y
If the data uses Y to decrement the card, then the card can't hold X
So violent n^2 can be done.
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;structp{intID; Doublex, y; BOOL operator< (Constp& B)Const{returnX <b.x;}} p[100050], p2[100050];BOOLcmpConstP &a,ConstP &B) { returnA.y <b.y;}DoubleDis (P &a, p &b) {return(a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y); }intMain () {intN; while(cin>>N) {if(n = =0) Break; DoubleD =1e8; for(inti =1; I <= N; i++) scanf ("%LF%LF", &p[i].x, &p[i].y), p2[i].x = p[i].x, p2[i].y =p[i].y; Sort (P2+1, p2+1+N, CMP); Sort (P+1, p+1+N); intTOT1 =0, Tot2 = -; for(intI1 =2, I2 =2, Li1 =1, Li2 =1; I1 <= n && i2 <=N;) { for(intj = li1; J >=1; j--) {D=min (d, Dis (P[I1], p[j])); if(((p[i1].x-p[j].x) * (p[i1].x-p[j].x) >= d) | | j =1) {i1++; li1 = i1-1; Break;} if(Tot1 >= Tot2) {TOT1 + = $; Li1 = J1; Break; } TOT1++; } for(intj = Li2; J >=1; j--) {D=min (d, Dis (P2[i2], p2[j])); if(((P2[I2].Y-P2[J].Y) * (P2[I2].Y-P2[J].Y) >= d) | | j =1) {i2++; li2 = i2-1; Break; } if(Tot2 >= tot1) {Tot2 + = $; Li2 = J1; Break; } Tot2++; }} printf ("%.2f\n", sqrt (d)/2); }}
Hdu1007 plane closest point pair (brute Force + dual-Threading optimization)