Hdu-4709-Herding

Source: Internet
Author: User

Question: Give the coordinates of N points, take some points from them to form a polygon, and find the minimum area of the polygon, output "Impossible" (number of test groups T <= 25, 1 <= N <= 100,-1000 <= coordinates Xi, Yi <= 1000 ). --> Minimum area. If yes, it must be a triangle. Determine whether a triangle can be formed at three points. If the slope is used, it is troublesome and there may be precision errors. Use the cross product to determine if the cross product of the two vectors is 0 ). Note: N can be 1 or 2, and a triangle cannot be determined.

 #include <cstdio>  #include <cmath>  #include <algorithm>    using namespace std;    const int maxn = 100 + 10;  const double eps = 1e-10;  const double INF = 1 << 30;    int N;    struct Point{      double x;      double y;      Point(double x = 0, double y = 0):x(x), y(y){}  }p[maxn];    typedef Point Vector;    Vector operator + (Point A, Point B){      return Vector(A.x + B.x, A.y + B.y);  }    Vector operator - (Point A, Point B){      return Vector(A.x - B.x, A.y - B.y);  }    Vector operator * (Point A, double p){      return Vector(A.x * p, A.y * p);  }    Vector operator / (Point A, double p){      return Vector(A.x / p, A.y / p);  }    double Cross(Vector A, Vector B){      return A.x * B.y - B.x * A.y;  }    double Area2(Point A, Point B, Point C){      return Cross(B-A, C-A);  }    int dcmp(double x){      if(fabs(x) < eps) return 0;      else return x < 0 ? -1 : 1;  }    void read(){      scanf("%d", &N);      for(int i = 0; i < N; i++) scanf("%lf%lf", &p[i].x, &p[i].y);  }    void solve(){      double Min = INF;      if(N >= 3){          for(int i = 0; i < N; i++)          for(int j = i+1; j < N; j++)              for(int k = j+1; k < N; k++) if(dcmp(Cross(p[j] - p[i], p[k] - p[i]))){                  double temp = fabs(Area2(p[i], p[j], p[k]));                  Min = min(Min, temp);              }      }      if(dcmp(Min - INF) == 0) puts("Impossible");      else printf("%.2f\n", Min/2);  }    int main()  {      int T;      scanf("%d", &T);      while(T--){          read();          solve();      }      return 0;  }  

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.