Herding

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

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

分析:求最小面积就是求所有点构成的所有三角形的最小面积,但是要注意选择构成三角形的三个点不能在一条线上,横,竖,斜不能在一条线上

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<cmath>
#include<iomanip>
#define INF 99999999
using namespace std; const int MAX=100+10;
double s[MAX][2]; double calculate(int i,int j,int k){
return fabs((s[j][0]-s[i][0])*(s[k][1]-s[i][1])-(s[k][0]-s[i][0])*(s[j][1]-s[i][1]))/2;
} int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=0;i<n;++i)scanf("%lf%lf",&s[i][0],&s[i][1]);
double sum=INF*1.0;
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j){
for(int k=j+1;k<n;++k){
if(s[i][1] == s[j][1] && s[j][1] == s[k][1])continue;
if((s[j][1]-s[i][1])/(s[j][0]-s[i][0]) == (s[k][1]-s[j][1])/(s[k][0]-s[j][0]))continue;
sum=min(sum,calculate(i,j,k));
}
}
}
if(sum == INF*1.0)printf("Impossible\n");
else printf("%.2lf\n",sum);
}
return 0;
}

hdu4709求三角形面积的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. golang实现已知三角形三点坐标,求三角形面积

    代码如下: func GetTriangleAreaByVector(x vector.Vector3,y vector.Vector3,z vector.Vector3) float64 { //根 ...

  7. 【C语言】已知三角形三边长,求三角形面积

    一. 数学基础: 已知三角形的三边,计算三角形面积,需要用到海伦公式: 即p=(a+b+c)/2 二. 算法: 输入三个边长,套用海伦公式计算面积,并输出. 可以先判断是否可以构成三角形,即任意两边之 ...

  8. java求三角形面积以及周长---封装

    /*时间: 2012-10-08作者: 烟大程序要求: 1.封装一类三角形对象Triangle,该类对象具有三条边的属性, 具有初始化三角形的功能.修改边长的功能.判断三条边能否构成三角形的功能. 求 ...

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

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

随机推荐

  1. 【转】 /etc/fstab功能详解

    [转] /etc/fstab功能详解 最近去客户现场时,遇到 了一个关于挂载文件/etc/fstab文件的问题,就写了一下/etc/fstab文件的作用一个文件中各个参数的含义.供大家参考有不正确的地 ...

  2. CentOS安装rar及用法

    1.下载安装rar wget http://www.rarsoft.com/rar/rarlinux-x64-5.4.b3.tar.gztar -zxvf rarlinux-x64-.tar.gz - ...

  3. C语言,单链表操作(增删改查)(version 0.1)

    这天要面试,提前把链表操作重新写了一遍.备份一下,以备不时之需. 希望有人能看到这篇代码,并指正. // File Name : list.h #include "stdafx.h" ...

  4. BZOJ 1270: [BeijingWc2008]雷涛的小猫( dp )

    简单的dp.. dp(i,j) = max(dp(x,y))+cnt[i][j], (x,y)->(i,j)是合法路径. 设f(i)= max(dp(x,y))(1≤x≤N, 1≤y≤i), g ...

  5. 使用SourceTree Push 出现 POST git-receive-pack (chunked) 的解决方法

    在使用SourceTree上传资料的时候,遇到 POST git-receive-pack (chunked) 从 stackoverflow 看到这样一则 This is a bug in Git; ...

  6. C# 继承细节

    假定没有为类定义任何显式的构造函数,这样编译器就会为所有的类提供默认的构造函数,在后台会进行许多操作,编译器可以很好地解决层次结构中的所有问题,每个类中的每个字段都会初始化为默认值.但在添加了一个我们 ...

  7. ubuntu中出现警告:Gtk-WARNING**: 无法在模块路径中找到主题引擎:“pixmap”

    版本 ubuntu12.04 上一篇中提到使用中文输入法,但是我在使用的时候发现当我启动IBus的时候出现了警告,如图 这个如何是好呢? 最终万能的度娘告诉我这么解决 故障原因: gtk引擎出现了故障 ...

  8. 关于VerilogHDL生成的锁存器

    总是会遇到有写文档中提到,不要生成锁存器.问题是 一: 什么叫锁存器 二 : 为什么不要生成锁存器 三 : 如何避免生成锁存器 好,现在就这三个问题,一一做出解答 一  什么叫锁存器 锁存器(Latc ...

  9. ListView与DataTable传递数据

    转载自:http://blog.sina.com.cn/s/blog_4b3485000100prhl.html 代码: using System; using System.Collections. ...

  10. H5前端面试题及答案(2)

    最近想着跳槽,但面试的邀约不多,内心有点烦躁.梳理梳理心情,跳槽季竞争也大,努力做好自己... 21.请设计一套方案,用于确保页面中js加载完全. <!doctype html> < ...