• hdu 4709 Herding


    Herding

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 886 Accepted Submission(s): 240

    Problem Description
    Little John is herding his father's cattles. As a lazy boy, he cannot tolerate chasing the cattles all the time to avoid unnecessary omission. Luckily, he notice that there were N trees in the meadow numbered from 1 to N, and calculated their cartesian coordinates (Xi, Yi). To herding his cattles safely, the easiest way is to connect some of the trees (with different numbers, of course) with fences, and the close region they formed would be herding area. Little John wants the area of this region to be as small as possible, and it could not be zero, of course.
     
    Input
    The first line contains the number of test cases T( T<=25 ). Following lines are the scenarios of each test case.
    The first line of each test case contains one integer N( 1<=N<=100 ). The following N lines describe the coordinates of the trees. Each of these lines will contain two float numbers Xi and Yi( -1000<=Xi, Yi<=1000 ) representing the coordinates of the corresponding tree. The coordinates of the trees will not coincide with each other.
     
    Output
    For each test case, please output one number rounded to 2 digits after the decimal point representing the area of the smallest region. Or output "Impossible"(without quotations), if it do not exists such a region.
     
    Sample Input
    1 4 -1.00 0.00 0.00 -3.00 2.00 0.00 2.00 2.00
     
    Sample Output
    2.00
     
    Source
     
    Recommend
    liuyiding
    就是求三角形的最小面积,不能用海伦公式,估计是有精度损失吧!
    #include <iostream>
    #include <math.h>
    #include <stdio.h>
    #include <string.h>
    using namespace std;
    #define inf 100000000.0
    double x[105],y[105];
    double ff(int i,int j,int k)
    {
        return fabs(x[i]*y[j]+y[i]*x[k]+x[j]*y[k]-x[k]*y[j]-x[j]*y[i]-x[i]*y[k])/2;
    }
    int main()
    {
        int tcase,i,n,j,k;
        scanf("%d",&tcase);
        while(tcase--)
        {
            scanf("%d",&n);
            for(i=0;i<n;i++)
            {
                scanf("%lf%lf",&x[i],&y[i]);
            }
            double maxx=inf;
            bool falg=true;
            for(i=0;i<n-2;i++)
                for(j=i+1;j<n-1;j++)
                    for(k=j+1;k<n;k++)
                    {
                        double tt=ff(i,j,k);
                        if(tt!=0.0)
                        maxx=min(maxx,tt),falg=false;
                    }
            if(!falg)
            printf("%.2lf
    ",maxx);
            else
            printf("Impossible
    ");
        }
        return 0;
    }
    


     
  • 相关阅读:
    ASP.NET Post方式提交
    MVC增加操作日志
    asp.net MVC 下拉多级联动及编辑
    redis基本数据类型之String
    关于idea下使用springinitializr创建项目时 初始化失败的解决
    Failed to read artifact descriptor for org.mybatis:mybatis:jar:2.2.1
    如何查看日志文件
    nginx 部署vue 以及同一端口下部署监听多个vue 项目
    JsonView 与JsonIgnore 使用
    vue 打包部署
  • 原文地址:https://www.cnblogs.com/riskyer/p/3313314.html
Copyright © 2020-2023  润新知