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. [Exceptions Spring 2] - Cannot create a session after the response has been committed

    2016-02-23 14:06:27,416 [http-bio-8080-exec-1] DEBUG [org.springframework.beans.factory.support.Defa ...

  2. [Done]com.aerospike.client.AerospikeException: Error Code 12: Bin type error

    今天遇到了一个问题:com.aerospike.client.AerospikeException: Error Code 12: Bin type error 异常栈: 网上找了一些资料:https ...

  3. Android Studio 怎样打开两个项目?

    欢迎转载: 请注明 原创Url

  4. 摘:C++ 枚举类型

    C++ 中的枚举类型继承于 C 语言.就像其他从 C 语言继承过来的很多特性一样,C++ 枚举也有缺点,这其中最显著的莫过于作用域问题——在枚举类型中定义的常量,属于定义枚举的作用域,而不属于这个枚举 ...

  5. Windows Mobile自动更新

    private static string m_CurrentPath; //取得作业平台 private static string Platform { get { return Environm ...

  6. mysql group replication 安装&配置详解

    一.原起: 之前也有写过mysql-group-replication (mgr) 相关的文章.那时也没有什么特别的动力要写好它.主要是因为在 mysql-5.7.20 之前的版本的mgr都有着各种各 ...

  7. laravel模型中打印sql语句

    模型中有个 ->toSql() 可以打印sql语句

  8. [原]SQL相关路径查询脚本

    --1.查询机器名 SELECT @@servername AS 机器名称 --查询已安装的SQL实例名 SELECT * FROM Sys.Servers --2.查询SQL安装路径 DECLARE ...

  9. sudo配置文件/etc/sudoers格式

    sudo的配置文件 sudoers 一般在 /etc 目录下. 不过不管 sudoers 文件在哪儿,sudo 都提供了一个编辑该文件的命令:visudo 来对该文件进行修改. 讲解sudo配置文件/ ...

  10. 使用阿里云Docker镜像加速

    使用docker官方的docker hub速度太慢,正好看到国内阿里云也做了docker镜像,于是想试试看阿里云的docker源.先附上 阿里云docker hub地址 .新用户需要注册成为开发者.打 ...