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

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
 思路:在n个点里面找出3个点,使三角形的面积最小
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <cmath>
#include <iostream>
#define INF 1 << 25
#define eps 1e-8
using namespace std;
struct node{
double x,y;
}a[];
int n;
int check(node a,node b,node c)//向量判断是否3点在同一直线
{
node v1, v2;
v1.x = a.x - b.x;
v1.y = a.y - b.y;
v2.x = c.x - b.x;
v2.y = c.y - b.y;
if(fabs(v1.x * v2.y - v2.x * v1.y) < eps ) return ;
else return ;
}
double calc(node a,node b,node c)//求面积
{
double res = ;
res = fabs(a.x * b.y + b.x * c.y + c.x * a.y - b.x * a.y - c.x * b.y - a.x * c.y);
return res/2.0;
}
void solve()
{
scanf("%d",&n);
for(int i = ; i <=n ; ++i)
scanf("%lf%lf",&a[i].x,&a[i].y);
if(n == || n == ) { printf("Impossible\n"); return; }
double ans = INF;
for(int i = ; i <= n ;++i)//暴力枚举
for(int j = i + ; j <=n ; ++j)
for(int k = j + ; k <= n ; ++k)
if(check(a[i],a[j],a[k])){
double now = calc(a[i],a[j],a[k]);
if(now < ans) ans = now;
}
// cout << ans <<endl;
if(ans != INF)
printf("%.2f\n",ans);
else printf("Impossible\n");
}
int main()
{
ios::sync_with_stdio();
int t;
scanf("%d",&t);
while(t--)
solve();
return ;
}

最新文章

  1. [转载]基于TFS实践敏捷-项目管理
  2. httpserver
  3. Allegro笔记三
  4. jquery中的$(document).ready()、JavaScript中的window.onload()以及body中的onload()的区别
  5. nodejs:grunt使用合并压缩的基本使用
  6. [ActionScript 3.0] AS3 访问舞台上元件的方法
  7. PHPExcel上传sae遇到: -1:fail to get xml content
  8. [HDU 4741]Save Labman No.004[计算几何][精度]
  9. error C2504: “CActiveXDocControl”: 基类没有定义
  10. Android Studio新手
  11. HDU 1728 逃离迷宫(DFS)
  12. dJango前言之 socketserver源码
  13. jqgrid 分页 (基于ashx)
  14. Ex3_7无向图二部图_十一次作业
  15. Intellij IDEA 设置启动JVM参数
  16. Java面试(一) -- 基础部分(1)
  17. MySQL 基础一 安装
  18. js作用域及闭包
  19. ant学习笔记-taskdef
  20. learngin uboot design parameter recovery mechanism

热门文章

  1. September 23rd 2016 Week 39th Friday
  2. 自定义UIDatePikerView
  3. 对象映射组件Tiny Mapper
  4. MongoDB基本命令
  5. Delphi中uses在interfeace和implementation中的区别
  6. mysql 查询优化规则
  7. 用.NET开发通用Windows App
  8. HR外包系统 - 工资计算-几种常见账单计算规则
  9. Android入门开发之SD卡读写操作(转)
  10. HDU 5869 Different GCD Subarray Query 离线+树状数组