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. Oracle执行计划——处理一种并行hint不生效的情况

    刚刚在itpub上看到有人在问并行hint不生效的一个问题.我做了实验也出现一样的问题,如下: 原因在这是小表,在联合时走索引了,加上full的hint,就可以启动并行的执行计划. 当然也可以采用pa ...

  2. 写了交互给后台后来不能用?bug多多多又找不到文件效率低?工作流程帮你优化起来~~~~

    前端工作流程(多方交互篇) 新的网页: 1.跟美工沟通,跟产品沟通,跟后台沟通.前两者主要是页面样式.后者主要是表单交互.用哪个框架之类的. 2.实现.(写清楚哪块是用什么验证方式的)→ 给后台. 3 ...

  3. ThinkPHP - 自动创建 + 自动验证 + 自动完成

    自动创建:创建数据模型. $User->create(); 自动验证:验证提交的表单数据. protected $_validate = array( array('verify','requi ...

  4. javascript 学习随笔3

    <html> <head> <script type="text/javascript"> function startTime() { var ...

  5. cURL实现get、post请求

    1.cURL介绍 cURL 是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 cURL 库.本文将介绍 cURL 的一些高级特性 ...

  6. QTexstStream的操作对象是QIODevice(因此QFile,QBuffer,QProcess,QTcpSocket都可以使用),或者QString

    QTexstStream用于读写纯文本以及HTML,XML等文本格式的文件,此类考虑了Unicode编码与系统本地编码的或其它任意编码之间的转换问题,别且明确地处理了因使用不同的操作系统而导致的行尾符 ...

  7. HDU SPFA算法 Invitation Cards

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1535 分析: 题意:求1点到其它点的最短距离之和+其它点到1点的最短距离之和 前面一部分直接用SPFA ...

  8. 关于C++的子类指针指向父类

    基类指针引用派生类对象 用基类指针引用一个派生类对象,由于派生类对象也是基类的对象,所以这种引用是安全的; 但是只能引用基类成员. 若试图通过基类指针引用那些只在派生类中才有的成员,编译器会报告语法错 ...

  9. 05-IOSCore - 单例模式、KVO

    单例模式 是设计模式之一,使用频率高,让数据或对象在程序的各个地方都能访问,保持唯一 要素: 各个地方都能访问方法 + 静态消息 只要导入类 就能访问 保持唯一 1.在静态消息内限制对象的创建 2.外 ...

  10. Starting the application on Mac does not work(拷贝platforms到不同的位置,才能解决问题),还可设置DYLD_PRINT_LIBRARIES=1 观察动态库

    In some rare cases it can happen that the application does not launch and there is no reaction after ...