Herding

时间:2022-03-27 16:09:52

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 ;
}

Herding的更多相关文章

  1. hduoj 4706 Herding 2013 ACM&sol;ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  2. HDU 4709:Herding

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  3. HDU Herding

    F - Herding Time Limit:1000MS       Memory Limit:32768KB      64bit IO Format:%I64d & %I64u Subm ...

  4. Herding(hdu4709)三点运用行列式求面积

    Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. HDU 4709 Herding (枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  6. HDUOJ---(4708)Herding

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  7. hdu 4709&colon;Herding(叉积求三角形面积&plus;枚举)

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  8. hdu - 4709 - Herding

    题意:给出N个点的坐标,从中取些点来组成一个多边形,求这个多边形的最小面积,组不成多边形的输出"Impossible"(测试组数 T <= 25, 1 <= N &lt ...

  9. hdu 4709 Herding hdu 2013 热身赛

    题意:给出笛卡尔坐标系上 n 个点,n不大于100,求出这些点中能围出的最小面积. 可以肯定的是三个点围成的面积是最小的,然后就暴力枚举,计算任意三点围成的面积.刚开始是求出三边的长,然后求面积,运算 ...

随机推荐

  1. Java使用velocity导出word

    效果展示: 使用word编辑好模板

  2. leetcode56&period; Merge Intervals

    题目要求: Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6 ...

  3. ThinkPHP访问不存在的模块跳到404页面

    在ACTION中新建一个文件EmptyAction.class.php,文件中的代码如下: <?php class EmptyAction extends Action{     functio ...

  4. 关于lua垃圾回收是否会执行&lowbar;&lowbar;gc函数呢?

    直接上代码 -- test.lua do local x = setmetatable({},{ __gc = function() print("works") end }) e ...

  5. Java语言基础(二) Java关键字

    Java语言基础(二) Java关键字 Java关键字比较多,我就不列举出来了,只记录一些常用的小知识点: ①Java的关键字只有小写. ②then.sizeof都不是Java的关键字,熟悉C++的程 ...

  6. frame嵌套的学习

    iframe嵌套的学习 具体代码<br /> window.onload=function(){<br /> var voteid=window.parent.parent.d ...

  7. Unity &plus; iBatis &plus; Asp&period;net Mvc 系统搭建

    Unity + iBatis + Asp.net Mvc 系统搭建 之前用EntityFramework Code First做了一些小项目,很是方便:后来在一个 Java 项目中接触了myBatis ...

  8. 出错:&lpar;unicode error&rpar; &&num;39&semi;unicodeescape&&num;39&semi; codec can&&num;39&semi;t decode bytes in position 8-9&colon; malformed &bsol;N character escape

    报错原因:python 中 \N 是换行的意思.这里要把 N 前面的 \ 转义一下.用  \\  代替即可. Nokia_mac = np.loadtxt('data\oui\\NokiaMac201 ...

  9. ajax的4个字母分别是什么意思

    Asynchronous JavaScript and XML 的缩写,异步的JavaScript和XML.在不重新加载整个页面的情况下 ,AJAX 与服务器交换数据并更新部分网页.

  10. jQuery 练习:tab 切换

    实现内容随菜单切换 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quot ...