Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1902    Accepted Submission(s): 540

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个点里面找出3个点,使三角形的面积最小
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <cmath>
#include <iostream>
#define INF 1 << 25
#define eps 1e-8
using namespace std;
struct node{
double x,y;
}a[];
int n;
int check(node a,node b,node c)//向量判断是否3点在同一直线
{
node v1, v2;
v1.x = a.x - b.x;
v1.y = a.y - b.y;
v2.x = c.x - b.x;
v2.y = c.y - b.y;
if(fabs(v1.x * v2.y - v2.x * v1.y) < eps ) return ;
else return ;
}
double calc(node a,node b,node c)//求面积
{
double res = ;
res = fabs(a.x * b.y + b.x * c.y + c.x * a.y - b.x * a.y - c.x * b.y - a.x * c.y);
return res/2.0;
}
void solve()
{
scanf("%d",&n);
for(int i = ; i <=n ; ++i)
scanf("%lf%lf",&a[i].x,&a[i].y);
if(n == || n == ) { printf("Impossible\n"); return; }
double ans = INF;
for(int i = ; i <= n ;++i)//暴力枚举
for(int j = i + ; j <=n ; ++j)
for(int k = j + ; k <= n ; ++k)
if(check(a[i],a[j],a[k])){
double now = calc(a[i],a[j],a[k]);
if(now < ans) ans = now;
}
// cout << ans <<endl;
if(ans != INF)
printf("%.2f\n",ans);
else printf("Impossible\n");
}
int main()
{
ios::sync_with_stdio();
int t;
scanf("%d",&t);
while(t--)
solve();
return ;
}

Herding的更多相关文章

  1. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  2. HDU 4709:Herding

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

  3. HDU Herding

    F - Herding Time Limit:1000MS       Memory Limit:32768KB      64bit IO Format:%I64d & %I64u Subm ...

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

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

  5. HDU 4709 Herding (枚举)

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

  6. HDUOJ---(4708)Herding

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

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

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

  8. hdu - 4709 - Herding

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

  9. hdu 4709 Herding hdu 2013 热身赛

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

随机推荐

  1. WinForm轻松实现自定义分页 (转载)

    转载至http://xuzhihong1987.blog.163.com/blog/static/267315872011315114240140/ 以前都是做web开发,最近接触了下WinForm, ...

  2. PCH文件配置路径

    "项目" >> Build  Settings >> Preflx Header >> $(SRCROOT)/项目名/XXX.pch

  3. poj1733(种类并查集+离散化)

    题目链接: http://poj.org/problem?id=1733 题意: 输入n表示有一个长度为n的0,1字符串, m表示接下来有m行输入, 接下来的m行输入中x, y, even表示第x到第 ...

  4. RxJava学习入门

    RxJava是什么 一个词:异步. RxJava 在 GitHub 主页上的自我介绍是 "a library for composing asynchronous and event-bas ...

  5. Android系统中默认值的意义列表

    转自:http://blog.csdn.net/yabg_zhi_xiang/article/details/51727844 在SettingsProvider中设置系统中默认值,我们可以在fram ...

  6. 七牛:关于图片 EXIF 信息中旋转参数 Orientation 的理解

    EXIF(Exchangeable Image File)是 “可交换图像文件” 的缩写,当中包含了专门为数码相机的照片而定制的元数据,可以记录数码照片的拍摄参数.缩略图及其他属性信息,简单来说,Ex ...

  7. Notice: Only variable references should be returned by reference(PHP版本兼容性问题)

    摘自:http://sushener.spaces.live.com/blog/cns!BB54050A5CFAFCDD!435.entry PHP5一个很让人恼火的一点就是BC(向后兼容)不是很理想 ...

  8. Delphi按下F1不能出现帮助文档的解决方法

    不光是Delphi,Windows里面所有的之所以无法打开.hlp帮助文档的问题都可以使用以下的方法来解决 问题:情况是这样的,不是打不开hlp帮助文档,按F1出现的是Windows的帮助.而Delp ...

  9. 【JAVA集合框架之Map】

    一.概述.1.Map是一种接口,在JAVA集合框架中是以一种非常重要的集合.2.Map一次添加一对元素,所以又称为“双列集合”(Collection一次添加一个元素,所以又称为“单列集合”)3.Map ...

  10. 常用的Java代码汇总

    1. 字符串有整型的相互转换           Java   1 2 <strong>Stringa=String.valueOf(2);   //integer to numeric ...