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;
    }
    


     
  • 相关阅读:
    jesperreport+ireport简单理解
    tomcat服务器奇异事件
    Spring+SpringMvc+Mybatis整合注意事项
    Websocket简单例子
    uploadify前台上传文件,java后台处理的例子
    违反完整约束条件 (XXX)
    插入排序
    选择排序
    冒泡算法(思路二)
    2-3树
  • 原文地址:https://www.cnblogs.com/riskyer/p/3313314.html
Copyright © 2011-2022 走看看