HDU Herding
F - Herding
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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的更多相关文章
- hdu 4709:Herding(叉积求三角形面积+枚举)
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 4709:Herding
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- hdu - 4709 - Herding
题意:给出N个点的坐标,从中取些点来组成一个多边形,求这个多边形的最小面积,组不成多边形的输出"Impossible"(测试组数 T <= 25, 1 <= N < ...
- HDU 4709 Herding (枚举)
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu 4709 Herding hdu 2013 热身赛
题意:给出笛卡尔坐标系上 n 个点,n不大于100,求出这些点中能围出的最小面积. 可以肯定的是三个点围成的面积是最小的,然后就暴力枚举,计算任意三点围成的面积.刚开始是求出三边的长,然后求面积,运算 ...
- HDU 4709 Herding 几何题解
求全部点组成的三角形最小的面积,0除外. 本题就枚举全部能够组成的三角形,然后保存最小的就是答案了.由于数据量非常少. 复习一下怎样求三角形面积.最简便的方法就是向量叉乘的知识了. 并且是二维向量叉乘 ...
- 【Herding HDU - 4709 】【数学(利用叉乘计算三角形面积)】
题意:给出n个点的坐标,问取出其中任意点围成的区域的最小值! 很明显,找到一个合适的三角形即可. #include<iostream> #include<cstdio> #in ...
- Herding(hdu4709)三点运用行列式求面积
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 学习数论 HDU 4709
经过杭师大校赛的打击,明白了数学知识的重要性 开始学习数论,开始找题练手 Herding HDU - 4709 Little John is herding his father's cattles. ...
随机推荐
- sort()方法理解
转作者:SMTNinja来源:知乎 下面这个排序函数展示了任何基于比较的排序算法 (comparison-based sorting algorithm) 都有的一段代码: 从大到小排序(一列东西, ...
- 2016年美国数学建模比赛(MCM/ICM) E题环境科学 Are we heading towards a thirsty planet? 人工精准翻译。
第二次参加建模,觉得建模太有趣了,用几天的时间,迅速学习新知识,并解决实际问题. ——————————————————————————————————————————————————————————— ...
- 某大神C#框架后台发送信息的查找及破解
最近在博客园瞎逛的时候,发现了某个大神发布的一个c#框架,一看框架,叫牛逼框架,嗯,装B效果太好了,界面很炫,虽然有很多的组件还是不怎么完善,但是,已经可以初步运用于项目了. 先来看看界面: 在进 ...
- ps 如何裁切图片成一定的长宽高比例
1打开一张图片然后点击拆件工具然后在面板上长宽高,按enter键盘,OK拆建完成
- JavaScript中Array.prototype.sort()的详解
摘抄来源:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort sor ...
- Python 调用shell
第一种,os.system("The command you want"). 这个调用相当直接,且是同步进行的,程序需要阻塞并等待返回.返回值是依赖于系统的,直接返回系统的调用返回 ...
- OSI模型第四层传输层--UDP协议
1.udp协议 UDP是OSI参考模型中一种无连接的传输层协议,它主要用于不要求分组顺序到达的传输中,分组传输顺序的检查与排序由应用层完成[2] ,提供面向事务的简单不可靠信息传送服务.UDP 协议 ...
- CentOS7 离线安装gcc/pcre-devel/openssl-devel/zlib-devel
1. 解压CentOS7操作系统安装镜像,进入到CentOS-7.0-1406-x86_64-DVD\Packages目录,这下面存储了很多rpm包. 2. 找到下面列出的rpm包,上传到CentOS ...
- 【C#】面试题整理
1.C#中类是否支持多继承?请说明原因.答:不支持,需要用接口来实现多继承 2.我们都知道一个类可以有多个构造函数,并且C#会在我们创建类的时候默认的提供一个无参的构造函数,当我实现了另外一个有参数的 ...
- Unity3D脚本使用:Random
实例: 为集合变量赋值,并运行,点击按钮,运行结果如图