zoukankan      html  css  js  c++  java
  • POJ 1912 凸包

    题目

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <cmath>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <map>
    #include <algorithm>
    #include <set>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long Ull;
    #define MM(a,b) memset(a,b,sizeof(a));
    const double eps = 1e-10;
    const int inf = 0x3f3f3f3f;
    const double pi=acos(-1);
    const int mod=100000000;
    
    struct Point{
       double x,y;
       //Point(){};
       Point(double xx=0,double yy=0):x(xx),y(yy){}
       bool read()
        {
            return ~scanf("%lf%lf", &x, &y);
        }
       bool operator<(const Point p) const{
           if(this->x!=p.x)
             return  this->x<p.x;
           else return this->y<p.y;
       }
       double dot(Point p)
       {
           return this->x*p.x+this->y*p.y;
       }
       double getA()
       {
           double A=atan2(this->y,this->x);
           if(A<-pi/2+eps) A+=2*pi;
           return A;
       }
       Point operator-(Point p)
       {
           return Point(this->x-p.x,this->y-p.y);
       }
    };
    
    double det(Point p,Point q)
    {
        return p.x*q.y-q.x*p.y;
    }
    
    int dcmp(double x)
    {
        if(fabs(x)<eps) return 0;
        else if(x>0) return 1;
        else return -1;
    }
    Point p[100005],ans[100005];
    double ang[100005];
    
    int Convex_hull(Point *p,int n,Point *ans)
    {
           sort(p+1,p+n+1);
           ans[1]=p[1];ans[2]=p[2];
           int w=2;
           for(int i=3;i<=n;i++)
           {
               int k=dcmp(det(p[i]-ans[w-1],ans[w]-ans[w-1]));
               while(dcmp(det(p[i]-ans[w-1],ans[w]-ans[w-1]))>0&&w>=2)
                  w--;
               ans[++w]=p[i];
           }
           int cur=w;
           ans[++w]=p[n-1];
           for(int i=n-2;i>=2;i--)
           {
               int k=dcmp(det(p[i]-ans[w-1],ans[w]-ans[w-1]));
               while(dcmp(det(p[i]-ans[w-1],ans[w]-ans[w-1]))>0&&w>=cur+1)
                 w--;
               ans[++w]=p[i];
           }
           return w;
    }
    
    int main()
    {
        int n;
        while(~scanf("%d",&n))
        {
            for(int i=1;i<=n;i++) p[i].read();
            int m=0;
            if(n>1) {m=Convex_hull(p,n,ans);}
            ans[m+1]=ans[0];
            for(int i=1;i<=m;i++)
                ang[i]=(ans[i+1]-ans[i]).getA();
            Point q[3];
            while(q[1].read())
            {
                q[2].read();
                int i=upper_bound(ang+1,ang+m+1,(q[2]-q[1]).getA())-ang;
                int j=upper_bound(ang+1,ang+m+1,(q[1]-q[2]).getA())-ang;
                if(n>1&&dcmp(det(q[2]-q[1],ans[i]-q[1]))*dcmp(det(q[2]-q[1],ans[j]-q[1]))<0)
                   printf("BAD
    ");
                else printf("GOOD
    ");
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    mysql find_int_set
    PHPSTROM8.0 注册码(7.1也可用)
    gym 101657 D
    gym101657 C
    poj 3525
    poj1279
    poj3335
    poj 1228
    poj 1873
    poj 2074
  • 原文地址:https://www.cnblogs.com/smilesundream/p/5402572.html
Copyright © 2011-2022 走看看