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. python标准库 正则表达式(re包)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 正则表达式(regular expression)主要功能是从字符串(string)中通过特定的模式(pattern) ...

  2. 阿里云rds linux平台使用wget 工具下载备份与日志文件

    1. 获取备份下载地址 RDS 控制台  备份恢复  数据备份,选择需要下载的备份集,点击“下载”. 点击“复制内网地址” 或 “复制外网地址” 来获取备份的 内网 或 外网 下载地址. 日志备份的地 ...

  3. python --文本文件的输入输出

    转自:http://www.cnblogs.com/vamei/archive/2012/06/06/2537868.html Python具有基本的文本文件读写功能.Python的标准库提供有更丰富 ...

  4. Android异步任务处理框架AsyncTask源代码分析

    [转载请注明出处:http://blog.csdn.net/feiduclear_up CSDN 废墟的树] 引言 在平时项目开发中难免会遇到异步耗时的任务(比方最常见的网络请求).遇到这样的问题.我 ...

  5. int main() 与 int _tmain()

    用过C的人都知道每一个C的程序都会有一个main(),但有时看别人写的程序发现主函数不是int main(),而是int _tmain(),而且头文件也不是<iostream.h>而是&l ...

  6. layui 数据表格 根据值(1=业务,2=机构)显示中文名称

    数据是用ThinkPHP5操作 类型是固定4个, 用layui templet - 自定义模板 方法一: {field:'type', title: '类型', width: 200, templet ...

  7. c++,当const char*为0时,不能将其直接赋给string

    下面程序会崩溃: const char* t_objName = (obj!=NULL)?obj->getName(): 0; string objName=t_objName; cout< ...

  8. Mysql时间存储类型优缺点?DATETIME?TIMESTAMP?INT?

    TIMESTAMP 4个字节储存;值以UTC格式保存;.时区转化 ,存储时对当前的时区进行转换,检索时再转换回当前的时区. DATETIME 8个字节储存;实际格式储存;与时区无关;datetime  ...

  9. AngularJS实现鼠标右键事件

    常规javascript鼠标右键直接在标签上加contextmenu="alert('a')"即可,现在angular通过directive来定义一个右键指令. app.direc ...

  10. [Jobdu] 题目1544:数字序列区间最小值

    题目描述: 给定一个数字序列,查询任意给定区间内数字的最小值. 输入: 输入包含多组测试用例,每组测试用例的开头为一个整数n(1<=n<=100000),代表数字序列的长度.接下去一行给出 ...