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. 探索Android中的Parcel机制(上)

    一.先从Serialize说起 我们都知道JAVA中的Serialize机制,译成串行化.序列化……,其作用是能将数据对象存入字节流其中,在须要时又一次生成对象.主要应用是利用外部存储设备保存对象状态 ...

  2. Python 中的list小结

    list的下标和子list list的下表从零开始,和C语言挺类似的,但是增加了负下标的使用. -len-----第一个元素 ......       ...... -2 ------ 倒数第二个元素 ...

  3. Struts+Tomcat搭建

    Struts+Tomcat搭建 tomcat使用(服务器端开发): 如果要安装Tomcat需要进行的配置:tomcat安装在c: \Tomcat CATALINA_HOME变量值设为: H:\Prog ...

  4. USACO March. 2012

    Connect the Cows Times17 水题 Landscaping Flowerpot Tractor 广搜 搜到边界就可以终止了 没什么难度 #include <stdio.h&g ...

  5. php上传文件,创建递归目录

    <?php $uid=$_REQUEST['uid']; $avatar = 'D:/avic/discuz/uc_server/data/avatar/'.get_avatar($uid, $ ...

  6. Tcl语言笔记之一

    1,一个TCL脚本可以包含一个或多个命令.命令之间必须用换行符或分号隔开 2,置换 substitution %set y x+100                               // ...

  7. C++成员变量与函数内存分配

    关于结构体和C++类的内存地址问题 C++类是由结构体发展得来的,所以他们的成员变量(C语言的结构体只有成员变量)的内存分配机制是一样的.下面我们以类来说明问题,如果类的问题通了,结构体也也就没问题啦 ...

  8. PLSQL Developer过期要注冊表

    打开执行输入 regedit 打表注冊表 删除 HKEY_CURRENT_USER\Software\Allround Automations HKEY_CURRENT_USER\Software\M ...

  9. Activity的创建和使用

    Activity: 1:创建一个类继承Activity或者它的子类 public class MainActivity extends Activity { @Override protected v ...

  10. CSS - ResetCss

    /* KISSY CSS Reset 理念:清除和重置是紧密不可分的 特色:1.适应中文 2.基于最新主流浏览器 */ /* 清除内外边距 */ body, h1, h2, h3, h4, h5, h ...