hdu 3549 Enumerate the Triangles

n^3暴力过了

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
struct point{
    double x,y;
}p[1001];
inline double dis(point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
    int t,n,cas=1;
    scanf("%d",&t);
    while(t--)
    {
        double ans=0x3f3f3f3f;
        scanf("%d",&n);
        for(int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);//cin>>p[i].x>>p[i].y;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                double tmp=dis(p[i],p[j]),tmp2;
                if(tmp*2>=ans) continue;
                for(int k=j+1;k<n;k++)
                {
                    if((p[j].y-p[i].y)*(p[k].x-p[i].x)==(p[k].y-p[i].y)*(p[j].x-p[i].x)) continue;
                    tmp2=tmp+dis(p[i],p[k])+dis(p[j], p[k]);
                    if(tmp2<ans) ans=tmp2;
                }
            }
        }
        printf("Case %d: ",cas++);
        if(ans<0x2f2f2f2f) printf("%.3lf\n",ans);
        else printf("No Solution\n");
        
    }
}		


你可能感兴趣的:(hdu 3549 Enumerate the Triangles)