• BZOJ 1113 Wall ——计算几何


    凸包第一题。

    自己认为自己写的是Andrew

    其实就是xjb写出来居然过掉了测试。

    刚开始把pi定义成了int,调了半天

    #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 eps 1e-10
    #define ll long long
    #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;}
    
    Vector operator + (Vector a,Vector b)
    {Vector ret;ret.x=a.x+b.x;ret.y=a.y+b.y;return ret;}
    
    Vector operator - (Vector a,Vector b)
    {Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;}
    
    Point operator + (Point a,Vector b)
    {Point ret;ret.x=a.x+b.x;ret.y=a.y+b.y;return ret;}
    
    Vector operator * (Vector a,double b)
    {Vector ret;ret.x=a.x*b;ret.y=a.y*b;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 dot (Vector a,Vector b)
    {return a.x*b.x+a.y*b.y;}
    
    double len(Vector a)
    {return sqrt(dot(a,a));}
    
    int n,l,top,sta[1005];
    
    Point a[1005];
    
    bool cmp(Point a,Point b)
    {return fabs(a.x-b.x)<eps?a.y<b.y:a.x<b.x;}
    
    int main()
    {
    	scanf("%d%d",&n,&l);
    	F(i,1,n) scanf("%lf%lf",&a[i].x,&a[i].y);
    	sort(a+1,a+n+1,cmp);
    	sta[++top]=1;
    	F(i,2,n)
    	{
    		while (top>=2&&((a[i]-a[sta[top]])*(a[sta[top]]-a[sta[top-1]]))<0) top--;
    		sta[++top]=i;
    	}
    	D(i,n-1,1)
    	{
    		while (top>=2&&((a[i]-a[sta[top]])*(a[sta[top]]-a[sta[top-1]]))<0) top--;
    		sta[++top]=i;
    	}
    	double ans=0;
    	F(i,2,top)
    	{
    		ans+=len(a[sta[i]]-a[sta[i-1]]);
    //		(a[sta[i]]-a[sta[i-1]]).print();
    	}
    	ans+=2.0*l*pi;
    //	printf("%.6f
    ",pi);
    //	printf("%.6f
    ",2.0*l*pi);
    	printf("%d
    ",(int)(ans+0.5));
    }
    

      

  • 相关阅读:
    Unity资源打包之Assetbundle
    集社交与金融为一体,平安天下通怎样推动互联网金融创新?
    json和pickle模块
    sys模块
    os模块
    random模块
    datetime模块
    time模块
    logging模块

  • 原文地址:https://www.cnblogs.com/SfailSth/p/6687354.html
Copyright © 2020-2023  润新知