水题  判一下能不能构成三角形  直接把最小的三角形面积直接爆出来

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#define INF 1000000007
using std::cout;
using std::endl;
double dat[110][2];
double solve(double a, double b, double c, double d, double e, double f)
{
    return fabs((c-e)*(b-d)-(c-e)*(f-d)/2-(a-e)*(b-f)/2-(c-a)*(b-d)/2);
}
bool find(int a, int b, int c)
{
    double A=(dat[c][0]-dat[a][0])*(dat[c][1]-dat[b][1]);
    double B=(dat[c][1]-dat[a][1])*(dat[c][0]-dat[b][0]);
    if(fabs(A-B)<1e-9) return false;
    return true;
}
int n,m;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&m);
        for(int i=0; i<m; i++)
            scanf("%lf %lf",&dat[i][0],&dat[i][1]);
        double mx=INF;
        bool ok=false;
        if(m<=2)
        {
             puts("Impossible");
            continue;
        }
        for(int i=0; i<m; i++)
        {
            for(int j=i+1; j<m; j++)
            {
                for(int k=j+1; k<m; k++)
                {
                    if(find(i,j,k))
                    {
                        ok=true;
                        double xx=solve(dat[i][0],dat[i][1],dat[j][0],dat[j][1],dat[k][0],dat[k][1]);
                        if(mx>xx) mx=xx;
                    }
                }
            }
        }
        if(ok) printf("%.2lf\n",mx);
        else puts("Impossible");
    }
    return 0;
}
View Code

 

posted on 2013-09-10 16:56  风流monkey  阅读(171)  评论(0编辑  收藏  举报