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