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


     
  • 相关阅读:
    创建本地源,使用yum install
    查找SCAN大量块的一个sql
    好的代码像首诗,差的代码像坨屎。
    ps
    eclipse程序正确运行却有红叉
    JS中文乱码解决方案
    初学JQuery
    初学JQuery 2
    大神的电脑软件
    eclipse导入已存在于workspace的项目
  • 原文地址:https://www.cnblogs.com/riskyer/p/3313314.html
Copyright © 2011-2022 走看看