zoukankan      html  css  js  c++  java
  • hdu 1348【凸包模板】

    #include<iostream>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    const int N=1005;
    const double eps=1e-8;
    int T,n,r,w,top;
    struct dian
    {
        double x,y;
        dian(double X=0,double Y=0)
        {
            x=X,y=Y;
        }
        dian operator + (const dian a) const
        {
            return dian(x+a.x,y+a.y);
        }
        dian operator - (const dian a) const
        {
            return dian(x-a.x,y-a.y);
        }
    }p[N],s[N],d;
    int cj(dian a,dian b)
    {
        return a.x*b.y-a.y*b.x;
    }
    double dis(dian a,dian b)
    {
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
    bool cmp(const dian &a,const dian &b)
    {
        double ar=cj(a-d,b-d);
    	return (ar>0)||((ar==0)&&a.x<b.x);
    }
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d",&n,&r);
            d.x=d.y=10000;top=0;
            for(int i=1;i<=n;i++)
            {
                scanf("%lf%lf",&p[i].x,&p[i].y);
                if(p[i].x<d.x||(p[i].x==d.x&&p[i].y<d.y))
                    d=p[i],w=i;
            }//cout<<endl<<d.x<<" "<<d.y<<endl;
            n--;
            for(int i=w;i<=n;i++)
                p[i]=p[i+1];
            sort(p+1,p+1+n,cmp);
            // for(int i=1;i<=n;i++)
                // printf("%f %f
    ",p[i].x,p[i].y);
            s[++top]=d,s[++top]=p[1];
            for(int i=2;i<=n;i++)
            {
                while(top>1&&cj(s[top]-p[i],s[top-1]-p[i])>=0)
    				top--;
                s[++top]=p[i];
            }
            double ans=2.0*3.1415926*(double)r;//cout<<ans<<endl;
            s[0]=s[top];
            for(int i=1;i<=top;i++)
                ans+=dis(s[i-1],s[i]);//,cout<<s[i].x<<" "<<s[i].y<<endl;
            printf("%.0lf
    ",ans);
    		if(T)
    			puts("");
        }
        return 0;
    }
    
  • 相关阅读:
    SDL_mixer 播放wav
    SDL_mixer 播放mp3
    [转]音频基础知识及编码原理
    [转]QT父子与QT对象delete
    [转]QT中嵌入SDL
    [转]PCM文件格式
    [转]ffmpeg库音频解码示例
    C# 向PivotItem中添加子控件
    初识 Windows Phone 7
    C#语言使用Windows phone 中的数据数据绑定
  • 原文地址:https://www.cnblogs.com/lokiii/p/8503207.html
Copyright © 2011-2022 走看看