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. Patterns-Observer

    http://book.javanb.com/java-design-patterns/index.html Java深入到一定程度,就不可避免的碰到设计模式(design pattern)这一概念, ...

  2. Spring事务属性具体解释

    Spring.是一个Java开源框架,是为了解决企业应用程序开发复杂性由Rod Johnson创建的.框架的主要优势之中的一个就是其分层架构,分层架构同意使用者选择使用哪一个组件,同一时候为 J2EE ...

  3. 深入理解javascript闭包【整理】

    原文链接:http://www.cn-cuckoo.com/2007/08/01/understand-javascript-closures-72.html 英文原文:http://www.jibb ...

  4. js判断是否为数组

      js判断是否为数组类型 CreateTime--2018年5月18日14:38:58 Author:Marydon 1.错误方式 使用typeof 返回的是object 2.正确方式 方式一:使用 ...

  5. 数据库-IO系统性能之衡量性能的几个指标

    转自http://storage.it168.com/a2011/0323/1169/000001169755_all.shtml 作为一个数据库管理员,关注系统的性能是日常最重要的工作之一,而在所关 ...

  6. Centos网络时好时超时问题解决

    近期公司使用的Centos突然出现网络不稳定现象,有公网,内部可以PING通外网,但是外部PING这个IP时,经常丢包现象,而且一丢包就是连续性的长达七八次,甚至十几次. 这个问题折腾了很长时间,因为 ...

  7. Android 屏幕自适应方向尺寸

    最近感觉要被屏幕适配玩死了…… 安卓的手机为虾米不能像苹果那样只有几个分辨率呢?为什么呢!!!!!!!阿门…… 目前想到有两种解决办法…… 第一种:   HTML5+CSS3+WebView交互……目 ...

  8. js ~取非运算符的妙用,将-1转为0(或假值)

    典型的运用场景就是indexOf

  9. mac appium 启动genymotion

    mac eclipse  appium 启动genymotion 模拟器,设置红框中的三项内容就可以.2个红色箭头不需要设置. 如果launch_avd 设置,就会提示:Emulator xxx no ...

  10. HttpPutFormContentFilter 和 ContextLoaderListener 讲解

    1 ContextLoaderListener 继承自ContextLoader,并且实现ServletContextListener接口. 肯定得实现这个接口了,不然怎么作为Servlet的监听器呢 ...