1 solutions
-
1
大概就是这样做的吧。
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; struct node { int x,y; }; const int NR=2e5+10; node p[NR],t[NR]; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-48; ch=getchar(); } return x*f; } bool cmpx(node x,node y) { return x.x<y.x; } bool cmpy(node x,node y) { return x.y<y.y; } double dist(node x,node y) { return sqrt(1.0*(x.x-y.x)*(x.x-y.x)+1.0*(x.y-y.y)*(x.y-y.y)); } double solve(int l,int r) { if(l==r) return 2e9; int mid=(l+r)/2,i,j,k,cnt=0; double w=min(solve(l,mid),solve(mid+1,r)); for(i=l;i<=r;i++) if(abs(p[mid].x-p[i].x)<w/2) t[++cnt]=p[i]; sort(t+1,t+cnt+1,cmpy); for(i=1;i+2<=cnt;i++) for(j=i+1;j<cnt && t[j].y-t[i].y<w/2;j++) for(k=j+1;k<=cnt && t[k].y-t[i].y<w/2;k++) w=min(w,dist(t[i],t[j])+dist(t[i],t[k])+dist(t[j],t[k])); return w; } int main() { // std::ios::sync_with_stdio(false); // std::cin.tie(0); // std::cout.tie(0); int n,i; n=read(); for(i=1;i<=n;i++) { p[i].x=read(); p[i].y=read(); } sort(p+1,p+n+1,cmpx); printf("%.6f\n",solve(1,n)); return 0; }
- 1
Information
- ID
- 3380
- Time
- 1000ms
- Memory
- 125MiB
- Difficulty
- 6
- Tags
- # Submissions
- 1
- Accepted
- 1
- Uploaded By