zoukankan      html  css  js  c++  java
  • 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验证控件的使用 拓荒者
    读书笔记:MFC单文档应用程序结构分析 拓荒者
    MFC单文档(SDI)全屏程序的实现 拓荒者
    jQuery的animate函数
    设备尺寸杂谈:响应性Web设计中的尺寸问题
    Yeoman学习与实践笔记
    IE对文档的解析模式及兼容性问题
    推荐给开发和设计人员的iPad应用
    几个移动应用统计平台
    颜色、网页颜色与网页安全色
  • 原文地址:https://www.cnblogs.com/riskyer/p/3313314.html
Copyright © 2011-2022 走看看