Herding

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

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
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  4822 4821 4820 4819 4818 

  
  叉积求三角形面积+枚举
  刚接触计算几何,这道题被坑了好几遍,好吧,我承认是我心急了,还是要沉下心来把基础知识先看一遍。
  回到这道题,三层循环枚举出构成三角形的三个点,然后用叉积求出三角形面积,如果结果等于0,说明当前三个点构不成三角形,枚举所有情况,输出符合条件的最小面积。
  另外不知道为什么海伦公式一直错。
 
 #include <iostream>
#include <iomanip>
using namespace std;
struct point{
double x,y;
}P[];
double getS(point a,point b,point c) //叉积求面积
{
return ((b.x - a.x) * (c.y - a.y) - (b.y - a.y)*(c.x - a.x))/;
}
int main()
{
int T,N;
cin>>T;
cout<<setiosflags(ios::fixed)<<setprecision();
while(T--){
cin>>N;
bool flag = false;
double minS=;
for(int i=;i<=N;i++)
cin>>P[i].x>>P[i].y;
for(int i=;i<=N;i++)
for(int j=;j<=N;j++)
if(i!=j)
for(int k=;k<=N;k++)
if(k!=i && k!=j){
double t = getS(P[i],P[j],P[k]);
if(t<) t=-t;
if(t<minS && t!=){
minS=t;
flag = true;
}
}
if(flag)
cout<<minS<<endl;
else
cout<<"Impossible"<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 4709:Herding(叉积求三角形面积+枚举)的更多相关文章

  1. HDU 2036 叉乘求三角形面积

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...

  2. POJ - 1654 利用叉积求三角形面积 去 间接求多边形面积

    题意:在一个平面直角坐标系,一个点总是从原点出发,但是每次移动只能移动8个方向的中的一个并且每次移动距离只有1和√2这两种情况,最后一定会回到原点(以字母5结束),请你计算这个点所画出图形的面积 题解 ...

  3. POJ 2954 /// 皮克定理+叉积求三角形面积

    题目大意: 给定三角形的三点坐标 判断在其内部包含多少个整点 题解及讲解 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 - 1 那么求内部整点就是 in = s + 1 - ...

  4. hdu 2036:改革春风吹满地(叉积求凸多边形面积)

    改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  5. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  6. HDU 4709 Herding 几何题解

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

  7. Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积

    Maximal Area Quadrilateral CodeForces - 340B 三点坐标求三角形面积(可以带正负,表示向量/点的不同相对位置): http://www.cnblogs.com ...

  8. TZOJ 2519 Regetni(N个点求三角形面积为整数总数)

    描述 Background Hello Earthling. We're from the planet Regetni and need your help to make lots of mone ...

  9. hdu4709求三角形面积

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

随机推荐

  1. 用css3选择器给你要的第几个元素添加不同样式方法【转发】

    下面我们来了解一下css选择器里面的几个 :only-child p:only-child 选择属于其父元素的唯一子元素的每个 <p> 元素. 3 :nth-child(n) p:nth- ...

  2. ftp protocol

    RFC http://www.w3.org/Protocols/rfc959/4_FileTransfer.html http://blog.chinaunix.net/uid-17238776-id ...

  3. iOS 全屏侧滑/UIScrollView/UISlider间滑动冲突

    代码地址如下:http://www.demodashi.com/demo/13848.html 效果预览 一.前期准备 有一个支持全屏侧滑返回的视图控制器ViewController,ViewCont ...

  4. 【linux】FTP添加用户,设置权限和目录

    一.目的,新建一个用户 test2,登录ftp,它只有自己的主目录权限,其他同级和上级目录没有权限 二.ftp安装.配置 yum -y install vsftpd //通过yum来安装vsftpd ...

  5. Php开发工具:PhpStorm=webstorm+php+db/SQL

    下载地址:https://www.jetbrains.com/zh/phpstorm/specials/phpstorm/phpstorm.html?utm_source=baidu&utm_ ...

  6. IO多路复用之poll

    1.基本知识 poll的机制与select类似,与select在本质上没有多大差别,管理多个描述符也是进行轮询,根据描述符的状态进行处理,但是poll没有最大文件描述符数量的限制.poll和selec ...

  7. (Windows Maven项目)Redis数据库的安装和操作实现

              Redis是一个内存数据库,他会把你写入当中的数据缓存到内存中,之后会周期性的往磁盘中写入.这篇文章中介绍的是在Windows环境下利用Maven工具编译运行Java文件实现Red ...

  8. atitit.编程语言的未来趋势与进化结果

    atitit.编程语言的未来趋势与进化结果 1 语言就像物种一样,会形成进化树,没有前途的分支将枯死脱落. 1 2 机器语言 1 3 汇编语言 2 4 C语言, 硬件抽象层 2 5 高级语言:java ...

  9. [svc]visio绘制模具

    visio2016狮子XL自定义运维模具下载: https://github.com/lannyMa/scripts/blob/master/%E7%BE%8E%E5%8C%96%E5%AE%9A%E ...

  10. BS Web窗体 动态修改WebConfig文件参数及数据库链接串

    WebConfig操作帮助类 /// /// ConfigurationOperator 的摘要说明 /// public class ConfigurationOperator : IDisposa ...