• BZOJ 2829 信用卡凸包 ——计算几何


    凸包裸题

    #include <map>
    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define F(i,j,k) for (int i=j;i<=k;++i)
    #define D(i,j,k) for (int i=j;i>=k;--i)
    #define ll long long
    #define eps 1e-8
    #define mp make_pair
     
    const double pi=acos(-1.0);
     
    struct Vector{
        double x,y;
        void print()
        {
            printf("Vector (%.3f,%.3f)
    ",x,y);
        }
    };
    struct Point{
        double x,y;
        void print()
        {
            printf("Point (%.3f,%.3f)
    ",x,y);
        }
    };
     
    double operator * (Vector a,Vector b)
    {return a.x*b.y-a.y*b.x;}
     
    Point operator + (Point a,Vector b)
    {Point ret;ret.x=a.x+b.x;ret.y=a.y+b.y;return ret;}
     
    Vector operator - (Point a,Point b)
    {Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;}
     
    double dist(Point a,Point b)
    {
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
     
    Vector Turn(Vector a,double b)
    {
        Vector ret;
    //  printf("Turn : 
    ");
    //  a.print(); printf("in %.6f
    ",b/pi*180);
        ret.x=a.x*cos(b)-a.y*sin(b);
        ret.y=a.y*cos(b)+a.x*sin(b);
    //  ret.print();
        return ret;
    }
     
    int n,top=0,cnt=0;
    double a,b,r,x,y,theta,ans=0;
    Vector v[4];
    int mov[4][2]={{1,1},{1,-1},{-1,1},{-1,-1}};
    Point p[500005];
    Point sta[500005];
     
    bool cmp(Point a,Point b)
    {
        return fabs(a.x-b.x)<eps?a.y<b.y:a.x<b.x;
    }
     
    void Andrew()
    {
        cnt=0;
        sort(p+1,p+top+1,cmp);
    //  F(i,1,top) p[i].print();
        sta[++cnt]=p[1];
        F(i,2,top)
        if (fabs(p[i].x-p[i-1].x)>eps||fabs(p[i].y-p[i-1].y)>eps){
    //      printf("Add : ");p[i].print();
            while (cnt>=2&&((sta[cnt]-sta[cnt-1])*(p[i]-sta[cnt]))<0) cnt--;
            sta[++cnt]=p[i];
    //      printf("Instack : 
    ");F(i,1,cnt) sta[i].print(); printf("
    
    ");
        }
        D(i,top-1,1)
        if (fabs(p[i].x-p[i+1].x)>eps||fabs(p[i].y-p[i+1].y)>eps){
            while (cnt>=2&&((sta[cnt]-sta[cnt-1])*(p[i]-sta[cnt]))<0) cnt--;
            sta[++cnt]=p[i];
        }
        F(i,1,cnt-1) ans+=dist(sta[i],sta[i+1]);
        ans+=r*2*pi;
        printf("%.2f
    ",ans);
    //  F(i,1,cnt) sta[i].print();
    }
     
    int main()
    {
        scanf("%d",&n);
        scanf("%lf%lf%lf",&a,&b,&r);
        a/=2;b/=2;a-=r;b-=r;
        F(i,0,3) v[i].x=mov[i][0]*b,v[i].y=mov[i][1]*a;
    //  printf("Over
    ");
        F(i,1,n)
        {
            scanf("%lf%lf%lf",&x,&y,&theta);
            Point now; now.x=x;now.y=y;
            F(j,0,3)
                p[++top]=now+Turn(v[j],theta);
        }
    //  F(i,1,top) p[i].print();
        Andrew();
    }
    

      

  • 相关阅读:
    第3章 文件I/O(4)_dup、dup2、fcntl和ioctl函数
    第3章 文件I/O(3)_内核数据结构、原子操作
    MyBatis Geneator详解<转>
    MapReduce原理<转>
    maven配置nexus
    myeclipse 上安装 Maven3<转>
    Lucene 工作原理<转>
    获取本工程的真实路径
    webservice文件上传下载
    fastjson常用操作
  • 原文地址:https://www.cnblogs.com/SfailSth/p/6686184.html
Copyright © 2020-2023  润新知