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