hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup

Herding

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

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棵树中选出M棵围成的区域面积最小。

换句话说就是求在一堆笛卡尔坐标中选出三个点组成的面积最小。

AC代码:

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#include<stack>
#include<map>
#include<cmath>
#include<string>
using namespace std;
#define N 1000000
struct Point{
double x;
double y;
}point[];
double area2(double x0, double y0 , double x1, double y1, double x2, double y2)
{
return fabs(x0*y1+x2*y0+x1*y2-x2*y1-x0*y2-x1*y0);
}
int main(){
int n;
int tcase;
scanf("%d", &tcase);
while(tcase--){
double minn = ;
bool flag = false;
scanf("%d", &n);
for(int i = ; i < n; i++){
scanf("%lf%lf", &point[i].x, &point[i].y);
}
if(n >= ){
for(int i = ; i < n-; i++){
for(int j = i+; j < n-; j++){
for(int k = j+; k < n; k++){
double x1, x2, x3, y1, y2, y3;
x1 = point[i].x; y1 = point[i].y;
x2 = point[j].x; y2 = point[j].y;
x3 = point[k].x; y3 = point[k].y;
double num = area2(x1, y1, x2, y2, x3, y3);
num /= 2.0;
if(num < minn && num != ){
minn = num;
flag = true;
}
}
}
}
}
if(flag)
printf("%.2lf\n", minn);
else
printf("Impossible\n");
}
return ;
}

hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup的更多相关文章

  1. hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  2. hduoj 4706 Children&#39;s Day 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4706 Children's Day Time Limit: 2000/1000 MS (Java/Others) ...

  3. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  4. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  5. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

  6. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

  7. 2013 ACM/ICPC Asia Regional Online —— Warmup

    1003 Rotation Lock Puzzle 找出每一圈中的最大值即可 代码如下: #include<iostream> #include<stdio.h> #inclu ...

  8. HDU 4714 Tree2cycle(树状DP)(2013 ACM/ICPC Asia Regional Online ―― Warmup)

    Description A tree with N nodes and N-1 edges is given. To connect or disconnect one edge, we need 1 ...

  9. HDU 4749 Parade Show 2013 ACM/ICPC Asia Regional Nanjing Online

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749 题目大意:给一个原序列N,再给出一个序列M,问从N中一共可以找出多少个长度为m的序列,序列中的数 ...

随机推荐

  1. 设置session失效时间

    以X5部署在Tomcat上为例,说明如何设置session失效时间. 可以设置session失效时间的地点有三处,分别是 1.BusinessServer的session设置 \runtime\Bus ...

  2. PHP5 mysqli 教程

    mysqli提供了面向对象和面向过程两种方式来与数据库交互,分别看一下这两种方式. 1.面向对象 在面向对象的方式中,mysqli被封装成一个类,它的构造方法如下: __construct ([ st ...

  3. XPS to Blender 2.7x

    XPS to Blender 2.7x(Blender internal the easy way) Things we are gonna need are Blender 2.7x www.ble ...

  4. 蓝牙的L2CAP协议

    1.概述     L2CAP能向上层提供面向连接的或者无连接的数据服务,拥有multiplexing capability and segmentation and reassembly operat ...

  5. TCP粘包

    一.通信协议TCP/UDP: TCP(transport control protocol,传输控制协议)是面向连接的,面向流的,提供高可靠性服务.客户端和服务器端都要有一一成对的socket, 因此 ...

  6. zepto源码--extend--学习笔记

    对象继承函数: $.extend(){},默认传递一个参数,需要继承的对象目标.函数展示: 最终实现的过程,需要调用工具函数extend,首先分析extend函数. 默认传递三个参数,继承的目标对象- ...

  7. input的type属性的修改

    记录一下成长的历程吧! 刚开始写,没什么文笔,也没什么技术含量,可能主要的是纪录一下平常工作学习中遇到的问题,以及解决的办法吧.或者只有问题,没有解决办法. 前两天项目中遇到的一个问题,由于之前一直没 ...

  8. gridcontrol中使用右健菜单popupMenu1

    private void gridView1_ShowGridMenu(object sender, DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs ...

  9. 实验一补充内容 Java开发环境的熟悉-刘蔚然

    本次实验 PSP时间统计 步骤 耗时百分比 需求分析 5% 设计 10% 代码实现 67% 测试 15% 分析总结 3%

  10. linux root不能用

    在操作查看vi /etc/passwd 查看用户信息时,不小心修改了root的用户名改成了eoot,这样在切换到普通用户后,就切不回root,即使明明知道用户名是eoot,也知道原来的root密码,但 ...