zoukankan      html  css  js  c++  java
  • HDU 4709 Herding (枚举)

    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.
     
    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
     

     枚举三个点,找出面积最小的三角形

     1 /* *******************************************
     2 Author       : kuangbin
     3 Created Time : 2013年09月08日 星期日 13时19分17秒
     4 File Name    : 1004.cpp
     5 ******************************************* */
     6 
     7 #include <stdio.h>
     8 #include <algorithm>
     9 #include <iostream>
    10 #include <string.h>
    11 #include <vector>
    12 #include <queue>
    13 #include <set>
    14 #include <map>
    15 #include <string>
    16 #include <math.h>
    17 #include <stdlib.h>
    18 #include <time.h>
    19 using namespace std;
    20 
    21 const double eps = 1e-8;
    22 int sgn(double x)
    23 {
    24     if(fabs(x) < eps)return 0;
    25     if(x < 0)return -1;
    26     else return -1;
    27 }
    28 struct Point 
    29 {
    30     double x,y;
    31     Point(double _x = 0,double _y = 0)
    32     {
    33         x = _x;
    34         y = _y;
    35     }
    36     Point operator -(const Point &b)const
    37     {
    38         return Point(x - b.x, y-b.y);
    39     }
    40     double operator ^(const Point &b)const
    41     {
    42         return x * b.y - y * b.x;
    43     }
    44     void input()
    45     {
    46         scanf("%lf%lf",&x,&y);
    47     }
    48 };
    49 Point p[110];
    50 int main()
    51 {
    52     //freopen("in.txt","r",stdin);
    53     //freopen("out.txt","w",stdout);
    54     int T;
    55     int n;
    56     scanf("%d",&T);
    57     while(T--)
    58     {
    59         scanf("%d",&n);
    60         for(int i = 0;i < n;i++)
    61             p[i].input();
    62         bool flag = false;
    63         double ans = 1e20;
    64         for(int i = 0; i < n;i++)
    65             for(int j = i+1;j < n;j++)
    66                 for(int k = j+1;k < n;k++)
    67                 {
    68                     double area = (p[i]-p[j])^(p[k]-p[i]);
    69                     area = fabs(area)/2;    
    70                     if(sgn(area) == 0)continue;
    71                     flag = true;
    72                     ans = min(ans,area);
    73                 }
    74         if(!flag)
    75             printf("Impossible
    ");
    76         else printf("%.2f
    ",ans);
    77     }
    78     return 0;
    79 }
  • 相关阅读:
    Java+Spring Boot+Shiro前后端分离权限基础框架
    201809~201810 期推荐文章
    Spring Boot 2.0.2 教程
    201808 期推荐文章
    201807 期推荐文章
    Simple-Mult-SSM 基于Simple-SSM扩展Hessian注解的javaweb前后端分离SSM基础框架
    hexo + github 搭建博客系列教程汇总
    DockPanel与GeckoFX、ChrominumFX、CefSharp结合使用问题
    APP并非一个人在战斗,还有API—Xamarin.Android回忆录
    我正在使用Xamarin的跨平台框架—Xamarin.Android回忆录
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3308689.html
Copyright © 2011-2022 走看看