5 0 0 2 0 2 1 1 2 0 1
6.000000
思路:枚举四个点必然超时。所以对每一个点找最近的三个点。对这四个点枚举所有可能的多边形。即枚举对角ab,ac,ad 即可。
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> #include <stack> #include <map> #include <string> #define LL long long #define DB double using namespace std; int n; struct cpoint{ int x,y; void get(){scanf("%d%d",&x,&y);} }; DB dist(cpoint a,cpoint b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+0.0); } DB ss(cpoint a,cpoint b,cpoint c,cpoint d) { DB ans1 = dist(a,b)+dist(a,c)+dist(b,d)+dist(c,d); DB ans2 = dist(a,b)+dist(a,d)+dist(b,c)+dist(c,d); DB ans3 = dist(a,d)+dist(a,c)+dist(b,d)+dist(c,b); return min(ans1,min(ans2,ans3)); } struct nod{ int to; DB dis; bool operator<(const nod t)const { return dis<t.dis; } }; struct nn{ nod a[1009]; void sove(){sort(a,a+n);} } dis[1009]; cpoint re[1009]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif scanf("%d",&n); for(int i=0;i<n;i++) re[i].get(); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) dis[i].a[j].dis = dist(re[i],re[j]),dis[i].a[j].to=j; dis[i].sove(); } DB ans = 1e20; for(int i=0;i<n;i++) { ans= min(ans,ss(re[dis[i].a[0].to],re[dis[i].a[1].to],re[dis[i].a[2].to],re[dis[i].a[3].to])); }printf("%.6lf\n",ans); return 0; }