Herding

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

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
几何题,可以采用海伦公式,或者行列式
其中海伦公式为:sqrt(l-a)*(l-b)*(l-c)----》个人觉得此处做起来麻烦。。。
所以果断采用行列式....但需要注意精度问题....不然会错很多次的...lz就因为此wa20余次.....说出来都是泪..
代码:
     #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define maxn 1e10
using namespace std;
double area(double *a,double *b,double *c) //运用行列式求面积
{
double temp=(a[]*b[]+a[]*c[]+b[]*c[])-(c[]*b[]+b[]*a[]+a[]*c[]);
return temp<? -temp:temp;
}
int main()
{
double point[][],ans;
int t,n,i,j,k;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%lf%lf",&point[i][],&point[i][]);
ans=maxn;
for(i= ; i<n-; i++ )
{
for(j=i+;j<n-;j++)
{
for(k=j+;k<n;k++)
{
double temp=area(point[i],point[j],point[k])/2.0;
if(ans>temp&&temp>1e-)
ans=temp;
}
}
}
if(n<||ans<1e-||ans==maxn)
printf("Impossible\n");
else
printf("%.2lf\n",ans);
}
return ;
}

HDUOJ---(4708)Herding的更多相关文章

  1. HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)

    Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

  2. 使用OpenFiler来模拟存储配置RAC中ASM共享盘及多路径(multipath)的测试

    第一章 本篇总览 之前发布了一篇<Oracle_lhr_RAC 12cR1安装>,但是其中的存储并没有使用多路径,而是使用了VMware自身提供的存储.所以,年前最后一件事就是把多路径学习 ...

  3. PHP5.5.38版本Zend Guard loader for 5.5安装(详细)

    第一次在博客园写东西记录自己,不,可以说第一次在网上写东西记录自己,我只是个菜鸟,具体的不太懂, 但是作为一个菜鸟我肯定把我遇到的问题给详细的表述出来,大神勿喷.在安装Zend Guard loade ...

  4. Angular2入门系列教程7-HTTP(一)-使用Angular2自带的http进行网络请求

    上一篇:Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数 感觉这篇不是很好写,因为涉及到网络请求,如果采用真实的网络请求,这个例子大家拿到手估计还要自己写一个web ...

  5. Angular2学习笔记(1)

    Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...

  6. ASP.NET Core 之 Identity 入门(一)

    前言 在 ASP.NET Core 中,仍然沿用了 ASP.NET里面的 Identity 组件库,负责对用户的身份进行认证,总体来说的话,没有MVC 5 里面那么复杂,因为在MVC 5里面引入了OW ...

  7. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  8. Online Judge(OJ)搭建(第一版)

    搭建 OJ 需要的知识(重要性排序): Java SE(Basic Knowledge, String, FileWriter, JavaCompiler, URLClassLoader, Secur ...

  9. 如何一步一步用DDD设计一个电商网站(九)—— 小心陷入值对象持久化的坑

    阅读目录 前言 场景1的思考 场景2的思考 避坑方式 实践 结语 一.前言 在上一篇中(如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成),有一行注释的代码: public interfa ...

  10. 如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成

    阅读目录 前言 建模 实现 结语 一.前言 前面几篇已经实现了一个基本的购买+售价计算的过程,这次再让售价丰满一些,增加一个会员价的概念.会员价在现在的主流电商中,是一个不大常见的模式,其带来的问题是 ...

随机推荐

  1. HTTP协议状态码详解(HTTP Status Code)(转)

    原文链接:HTTP协议状态码详解(HTTP Status Code) 使用ASP.NET/PHP/JSP 或者javascript都会用到http的不同状态,一些常见的状态码为: 200 – 服务器成 ...

  2. 使用SGD(Stochastic Gradient Descent)进行大规模机器学习

    原贴地址:http://fuliang.iteye.com/blog/1482002  其它参考资料:http://en.wikipedia.org/wiki/Stochastic_gradient_ ...

  3. 基于at91rm9200的i2c分析(DS1307实时时钟芯片)

    board-ek.c 构造i2c_board_info结构体 static struct i2c_board_info __initdata ek_i2c_devices[] = {     {    ...

  4. 使用Topshelf 5步创建Windows 服务

    使用Topshelf创建Windows 服务简要的介绍了创建Windows服务的另一种方法,老外的一篇文章Create a .NET Windows Service in 5 steps with T ...

  5. Android实现随机验证码——自定义View

    一.问题描述 熟悉web开发中童鞋们都知道为了防止恶意破解.恶意提交.刷票等我们在提交表单数据时,都会使用随机验证码功能.在Android应用中我们同样需要这一功能,该如何实现呢,下面我们就自定义一个 ...

  6. 使用ViewDragHelper打造属于自己的DragLayout(抽屉开关 )

    使用ViewDragHelper打造属于自己的DragLayout(抽屉开关 ) DrawLayout这个自己定义的空间非经常见.qq,网易新闻.知乎等等,都有这样的效果,那这样的效果是如何实现的呢? ...

  7. python中 对文件的读写操作 以及如何边写入 边保存flush()

    转自:https://blog.csdn.net/t8116189520/article/details/78854708 首先 python中打开文件大致常用的几类如下: 1.写入文件write # ...

  8. 数字签名算法(C#)

    public static string GetSHA1Method(string strSource) { string strResult = ""; //Create Sys ...

  9. matlab中将矩阵按照行打乱顺序的一个例子

    来自百度百科: A = [1, 2, 3; 4, 5, 6; 7, 8, 9; 10, 11, 12] rowrank = randperm(size(A, 1)); % 随机打乱的数字,从1~行数打 ...

  10. Ipad也怕冷?!

    今天,说一Ipad充不了电,我想才没买好久,这么快电池就坏了呀.难道买到歪货了? 它的表现是充电线一接上去,电池指示有反应,也有"闪电"标志,就是充不进去电.本来想打客服的,还是先 ...