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. C语言与汇编“硬在哪里”——什么是面向硬件?

    Jack:为什么说C/C++语言是偏向硬件的语言呢? 我:这是把C与java等无指针/引用类编程语言相比较而得出的结论.因为java在j2ee的框架下,写的代码仅仅是逻辑,本质上和写shell脚本没啥 ...

  2. Spring实战——通过Java代码装配bean

    上篇说的是无需半行xml配置完成bean的自动化注入.这篇仍然不要任何xml配置,通过Java代码也能达到同样的效果. 这么说,是要把上篇的料拿出来再煮一遍? 当然不是,上篇我们几乎都在用注解的方式如 ...

  3. Kattis -Bus Numbers

    Bus Numbers Your favourite public transport company LS (we cannot use their real name here, so we pe ...

  4. liunx服务器常见监控指标

    1. CPU Utilization 英文翻译就是CPU的利用率75%以上就比较高了(也有说法是80%或者更高).有的博客上说除了这个指标外,还要结合Load Average和Context Swit ...

  5. sass---Sass混合宏、继承、占位符

    混合宏-声明混合宏如果你的整个网站中有几处小样式类似,比如颜色,字体等,在 Sass 可以使用变量来统一处理,那么这种选择还是不错的.但当你的样式变得越来越复杂,需要重复使用大段的样式时,使用变量就无 ...

  6. oracle登录时shared memory realm does not exist的解决方法

    解决办法:1.用CMD进入命令行2.sqlplus /nolog 3.conn / as sysdba4.startup   然后用sqlplus进入命令  

  7. CentOS7安装完毕,重新开机启动后显示: Initial setup of CentOS Linux 7 (core)

    CentOS7安装完毕,重新开机启动后显示: Initial setup of CentOS Linux 7 (core) 1) [x] Creat user 2) [!] License infor ...

  8. MAC OS 常用软件及开发工具

    1.各个版本的 Mac OS 链接: http://pan.baidu.com/s/1mgDtCi0 密码: 4y3u 2.Xcode xcode_4.6.3 链接: http://pan.baidu ...

  9. android 控件注意点

    控件一:listview 问题一:当listview的item中存在按钮这种控件时 item点击不能响应问题? 解决方案:在item的自定义控件的最外层空间 上添加属性 android:descend ...

  10. swift3.0 原生GET请求 POST同理

    swift3.0 原生GET请求  POST同理 func getrequest(){ let url = URL(string: "http://117.135.196.139:" ...