Herding

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

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
 

枚举三个点,找出面积最小的三角形

 /* *******************************************
Author : kuangbin
Created Time : 2013年09月08日 星期日 13时19分17秒
File Name : 1004.cpp
******************************************* */ #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; const double eps = 1e-;
int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return -;
}
struct Point
{
double x,y;
Point(double _x = ,double _y = )
{
x = _x;
y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x, y-b.y);
}
double operator ^(const Point &b)const
{
return x * b.y - y * b.x;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
};
Point p[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
int n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i = ;i < n;i++)
p[i].input();
bool flag = false;
double ans = 1e20;
for(int i = ; i < n;i++)
for(int j = i+;j < n;j++)
for(int k = j+;k < n;k++)
{
double area = (p[i]-p[j])^(p[k]-p[i]);
area = fabs(area)/;
if(sgn(area) == )continue;
flag = true;
ans = min(ans,area);
}
if(!flag)
printf("Impossible\n");
else printf("%.2f\n",ans);
}
return ;
}

最新文章

  1. P​D​F​二​次​开​发​_​i​S​t​y​l​e​P​D​F​表​单​域​的​填​充
  2. 【Aaronyang原创】用linq取出一个集合中重复的数据
  3. zhx and contest (枚举  + dfs)
  4. n-1位数
  5. ng-blur失去焦点执行事件
  6. SQL技巧之分类汇总
  7. Asp.net 网站发布之文件系统方式
  8. SAP MM ME21N 创建PO时报错 - Net price in CNY becomes too large –
  9. H - Partial Tree HDU - 5534 (背包)
  10. Jumpserver之安装在CentOS主机步骤
  11. socket的阻塞与非阻塞,同步与非同步
  12. RabbitMQ 在 web 页面 创建 exchange, queue, routing key
  13. oldboy s21day01
  14. 没有系列化导致错误:java.io.NotSerializableException: com.bjpowernode.bean.Team
  15. ajax读取txt文本时乱码的解决方案
  16. linux shell实现 URL 编码/解码方法
  17. HDU4417(SummerTrainingDay08-N 主席树)
  18. 浏览器同源策略,跨域请求jsonp
  19. Atom 检测php错误扩展linter-php
  20. js完美的div拖拽实例代码

热门文章

  1. Java Web 1-开发环境搭建(未完待续)
  2. python dict交换key value值
  3. shell中的特殊符号总结
  4. java 多线程总结篇1之——基本概念
  5. SQL中的注释语句
  6. 更改MyEclipse中的src目录的浏览方式
  7. hadoop集群的搭建(分布式安装)
  8. Elasticsearch环境准备(一)
  9. Pytho并发编程-利用协程实现简单爬虫
  10. gp数据库运维