F - Herding

Time Limit:1000MS       Memory Limit:32768KB      64bit IO Format:%I64d & %I64u

Submit Status

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

____

水题,直接枚举就可过。。

忘了用EPS 浮点数误差有问题

还有就是卡了一下输入,一开始判断n<3直接就CONTINUE了,这样接下来其他数据会出错。

代码如下:

#include<cstdio>

#include<algorithm>

#include<cmath>

#include<iostream>

using namespace std ;

#define N 110

#define eps 1e-8

struct

{

       doublex,y;

} array[N];

double area( double x1 , double y1 , doublex2 , double y2 ,double x3 , double y3 )

{

       returnfabs( 0.5 * ( x1*y2+x3*y1+x2*y3-x3*y2-x1*y3-x2*y1) ) ;

}

int main()

{

       intt ;

       cin>> t ;

       for(int i = 1 ; i<= t ; i++)

              {

                     intn ;

                     cin>> n ;

                     for(int i = 1 ; i<= n ; i++)

                            cin>> array[i].x >> array[i].y;

                     if(n < 3 )

                            {

                                   cout<<"Impossible" << endl ;

                                   continue;

                            }

                     doublemin = 99999999;

                     intflag = 1;

                     for(int i = 1 ; i <=n; i++)

                            {

                                   for(int j = i+1 ; j<=n ; j++)

                                          {

                                                 for(int k = j+1 ; k<= n; k++)

                                                        {

                                                               doubletemp =  area( array[i].x , array[i].y ,array[j].x,array[j].y,array[k].x,array[k].y) ;

                                                               if(fabs(temp) >= eps && temp <= min)

                                                                      {

                                                                             min= temp ;

                                                                             flag= 0 ;

                                                                      }

                                                        }

                                          }

                            }

                     if(flag == 0 )

                            printf("%.2lf\n",min);

                     else

                            cout<<"Impossible" << endl ;

              }

       return0 ;

}

HDU Herding的更多相关文章

  1. hdu 4709:Herding(叉积求三角形面积+枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  2. HDU 4709:Herding

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  3. hdu - 4709 - Herding

    题意:给出N个点的坐标,从中取些点来组成一个多边形,求这个多边形的最小面积,组不成多边形的输出"Impossible"(测试组数 T <= 25, 1 <= N < ...

  4. HDU 4709 Herding (枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. hdu 4709 Herding hdu 2013 热身赛

    题意:给出笛卡尔坐标系上 n 个点,n不大于100,求出这些点中能围出的最小面积. 可以肯定的是三个点围成的面积是最小的,然后就暴力枚举,计算任意三点围成的面积.刚开始是求出三边的长,然后求面积,运算 ...

  6. HDU 4709 Herding 几何题解

    求全部点组成的三角形最小的面积,0除外. 本题就枚举全部能够组成的三角形,然后保存最小的就是答案了.由于数据量非常少. 复习一下怎样求三角形面积.最简便的方法就是向量叉乘的知识了. 并且是二维向量叉乘 ...

  7. 【Herding HDU - 4709 】【数学(利用叉乘计算三角形面积)】

    题意:给出n个点的坐标,问取出其中任意点围成的区域的最小值! 很明显,找到一个合适的三角形即可. #include<iostream> #include<cstdio> #in ...

  8. Herding(hdu4709)三点运用行列式求面积

    Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. 学习数论 HDU 4709

    经过杭师大校赛的打击,明白了数学知识的重要性 开始学习数论,开始找题练手 Herding HDU - 4709 Little John is herding his father's cattles. ...

随机推荐

  1. Maven 插件 maven-tomcat7-plugin - 常用命令及配置

    常用命令 tomcat7:deploy 说明:部署 WAR 到 Tomcat tomcat7:help 说明:查看插件帮助信息 tomcat7:run 说明:支行当前项目 配置 <project ...

  2. SSH三大框架的基本整合以及常见错误的解决方法

    一.新建项目 eclipse->file->new->other->Dynamic Web Project,project name为sshDemo 二.下载jar包 1.st ...

  3. 【Zookeeper】源码分析之Watcher机制(一)

    一.前言 前面已经分析了Zookeeper持久话相关的类,下面接着分析Zookeeper中的Watcher机制所涉及到的类. 二.总体框图 对于Watcher机制而言,主要涉及的类主要如下. 说明: ...

  4. ASP.NET Zero--10.一个例子(3)商品分类管理-新建

    1.打开Index视图 页面中添加一个按钮,代码如下: <div class="row margin-bottom-5"> <div class="co ...

  5. CKPlayer 只调用HTML5播放器时全屏问题 这只是Chrome浏览器的渲染bug

    如题,在系统中使用CKPlayer播放器,一切顺利,偶然发现没有全屏按钮, 正常的全屏按钮是这样的: 经过一步步调试,发现问题出在iframe, 当视频页面在iframe内时,全屏按钮不显示了,这个和 ...

  6. JavaScript中遍历数组 最好不要使用 for in 遍历

    先看一段代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  7. Docker - Docker基础讲义

    Docker Docker - 官网 Docker - Hub GitHub - Docker Docker中文社区 虚拟化技术 硬件级虚拟化(hardware-level-virtualizatio ...

  8. Maven之(二)Maven生命周期

    我们在开发项目的时候,不断地在编译.测试.打包.部署等过程,maven的生命周期就是对所有构建过程抽象与统一,生命周期包含项目的清理.初始化.编译.测试.打包.集成测试.验证.部署.站点生成等几乎所有 ...

  9. linux下如何查询jdk安装路径

    1:echo $JAVA_HOME 使用$JAVA_HOME的话能定位JDK的安装路径的前提是配置了环境变量$JAVA_HOME,否则如下所示,根本定位不到JDK的安装路径 [root@localho ...

  10. Fedora24 升级到25

    1 安装dnf-plugin-system-upgrade dnf install dnf-plugin-system-upgrade 2 更新软件包 dnf system-upgrade downl ...