首页 > 代码库 > hdu 4709 Herding (数学)

hdu 4709 Herding (数学)

///给你n个点 枚举三点求最小三角形面积
# include <algorithm>
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <math.h>
# include <string>
using namespace std;
int main()
{
    int t,n,i,j,k;
    double x[110],y[110],minn,s;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            scanf("%d",&n);
            for(i=0; i<n; i++)
                scanf("%lf %lf",&x[i],&y[i]);
            minn=999999999;
            int flag=0;
            if(n<=2)
                printf("Impossible\n");
            else
            {

                for(i=0; i<n; i++)
                {
                    for(j=i+1; j<n; j++)
                    {
                        for(k=j+1; k<n; k++)
                        {
                            if(x[i]==x[j]&&x[j]==x[k]||y[i]==y[j]&&y[j]==y[k])
                                s=0;
                          ///  s=fabs((x[i]-x[k])*(y[j]-y[k])-(x[j]-x[k])*(y[i]-y[k]))/2.0;///已知三点算面积
                              s=(1/2.0)*fabs(x[i]*y[j]+x[j]*y[k]+x[k]*y[i]-x[i]*y[k]-x[j]*y[i]-x[k]*y[j]);
                            if(s>=0.005)
                            {
                                minn=min(s,minn);
                                flag=1;
                            }
                        }
                    }
                }
                if(flag)
                    printf("%.2lf\n",minn);
                else
                    printf("Impossible\n");
            }
        }
    }
    return 0;
}

hdu 4709 Herding (数学)