Herding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2418    Accepted Submission(s): 705

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
 

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

题意:给出n个点的坐标,问取出其中任意点围成的区域的最小值!

这个当然是三角形咯!既然给定了点的坐标,直接使用两向量叉乘除以二便可以解决!


#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
#include<string.h>
struct ab
{
double x,y;
} ab[105];
double solve(int i,int j,int k)
{
double a=ab[i].x-ab[k].x;
double b=ab[j].y-ab[k].y;
double c=ab[i].y-ab[k].y;
double d=ab[j].x-ab[k].x;
return fabs(a*b-c*d)/2.0;
}
int main()
{
int N;
cin>>N;
while(N--)
{
int n;
cin>>n;
for(int i=0; i<n; i++)
cin>>ab[i].x>>ab[i].y;
double minn=0xffffffff;
for(int i=0; i<n; i++)
for(int j=i+1; j<n; j++)
for(int k=j+1; k<n; k++)
{
double t=solve(i,j,k);
t=fabs(t);
if(t<=1e-7)continue;
minn=minn>t?t:minn;
}
if(minn==0xffffffff)printf("Impossible\n");
else printf("%.2lf\n",minn);
}
return 0;
}

HDU 4709: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 HDU - 4709 Little John is herding his father's cattles. ...

  3. HDU - 6409:没有兄弟的舞会(数学+思维)

    链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...

  4. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  5. hdu - 4709 - Herding

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

  6. hdu 4709 Herding hdu 2013 热身赛

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

  7. HDU 4709 Herding 几何题解

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

  8. HDU 4709 Herding (枚举)

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

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

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

随机推荐

  1. RAC数据库迁移ASM磁盘组到其它存储

    环境介绍: 一共有两个磁盘组:crs和data:crs使用normal冗余:data使用外部冗余. 添加新的asm磁盘过程(略) 1.迁移前 SQL> select group_number, ...

  2. R语言putty中直接使用X11(Xming)绘图

    1.下载Xming地址 http://pan.baidu.com/s/1o6ilisU,安装,推荐默认安装在C盘,推荐快捷方式放在与putty快捷方式同一个文件夹: 2.打开putty,在SSH的X1 ...

  3. Lintcode: Topological Sorting

    Given an directed graph, a topological order of the graph nodes is defined as follow: For each direc ...

  4. SLF4简介

    The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logg ...

  5. 【Origin】时迁念昔

    -清明,未曾归,恰大门来沪,晨起准备,车道劳顿,隔五年而见一面,感时事变迁,物各两异,小道旁之争艳花木,觉道长且阻,叹而留记. 清明时节雨纷纷, 不辞跋涉见故人; 红花绿叶皆失色, 握手言欢语无伦. ...

  6. t4 multiple output sample

    <#@ output extension=".js" #> <#@ template debug="false" hostspecific=& ...

  7. yii遍历行下的每列数据(小1月考)

    效果图: 控制器(1种): //显示列表    public function actionList()    {        //实例化对象        $model= new Qiu();   ...

  8. java dyn proxy

    package dyn; public interface RealService { void buy(); } =================== package dyn; public cl ...

  9. JVM中启用逃逸分析

    -XX:+DoEscapeAnalysis 逃逸分析优化JVM原理我们知道java对象是在堆里分配的,在调用栈中,只保存了对象的指针.当对象不再使用后,需要依靠GC来遍历引用树并回收内存,如果对象数量 ...

  10. 夺命雷公狗---DEDECMS----2快速入门之玩转dede四大表之间的关系

    比如一个小说网站,网站里面有很多类型让我们的小说网他里面有很多种分类,如: 玄幻....奇幻....仙侠....武侠....文学....异界....都市....军事....历史....灵异....悬疑 ...