• P1452 Beauty Contest


    传送门

    求凸包周长,用旋转卡壳,具体可见yyb大佬的博客

    顺便一提这题暴力+随机化也能过

    暴力代码

    //minamoto
    #include<bits/stdc++.h>
    #define rint register int
    #define int long long
    using namespace std;
    #define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    char buf[1<<21],*p1=buf,*p2=buf;
    int read(){
        int res,f=1;char ch;
        while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
        for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
        return res*f;
    }
    const int N=100005;
    int x[N],y[N],ans=-1;int n;
    inline int dis(int i,int j){return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);}
    signed main(){
    //	freopen("testdata.in","r",stdin);
        srand(time(0));
        n=read();
        for(rint i=1;i<=n;++i)x[i]=read(),y[i]=read();
        while(clock()<CLOCKS_PER_SEC*0.8)
            for(rint i=rand()%n+1,j=1;j<=n;++j)ans=max(ans,dis(i,j));
        printf("%d
    ",ans);return 0;
    }
    

    旋转卡壳代码

    //minamoto
    #include<bits/stdc++.h>
    #define rint register int
    #define inf 0x3f3f3f3f
    using namespace std;
    #define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
    char buf[1<<21],*p1=buf,*p2=buf;
    int read(){
        int res,f=1;char ch;
        while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
        for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
        return res*f;
    }
    const int N=1e5+5;
    struct node{int x,y;}p[N],st[N];
    int n,k,top,ans;
    inline bool cmp(node a,node b){
        double A=atan2(a.y-p[1].y,a.x-p[1].x);
        double B=atan2(b.y-p[1].y,b.x-p[1].x);
        return A!=B?A<B:a.x<b.x;
    }
    inline int cross(node a,node b,node c){return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}
    inline int dis(node a,node b){return (b.y-a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x);}
    void get(){
        if(top==1)return (void)(ans=dis(st[0],st[1]));
        st[++top]=st[0];
        for(rint i=0,j=2;i<top;++i){
            while(cross(st[i],st[i+1],st[j])<cross(st[i],st[i+1],st[j+1]))j=(j+1)%top;
            ans=max(ans,max(dis(st[i],st[j]),dis(st[i+1],st[j])));
        }
    }
    int main(){
    //	freopen("testdata.in","r",stdin);
        n=read(),p[0]={inf,inf};
        for(rint i=1;i<=n;++i){
            p[i].x=read(),p[i].y=read();
            if(p[0].y>p[i].y||(p[0].y==p[i].y&&p[0].x>p[i].x))p[0]=p[i],k=i;
        }
        swap(p[k],p[1]),sort(p+2,p+1+n,cmp);
        st[0]=p[1],st[1]=p[2],top=1;
        for(rint i=3;i<=n;++i){
            while(top&&cross(st[top-1],p[i],st[top])>=0)--top;
            st[++top]=p[i];
        }
        get();printf("%d
    ",ans);return 0;
    }
    
  • 相关阅读:
    定义结构体
    UML建模需求分析常用的UML图
    UML建模EA模型的组织
    优化Python脚本替换VC2005/2008工程x64配置
    C++插件框架已在 Mac OS X 下编译通过
    《iPhone开发快速入门》交流提纲
    X3插件框架发布v1.1.3
    从零开始创建一个插件
    Google论坛什么时候又可以使用的
    我的第一个Py脚本:批量替换VC工程中的x64条件定义配置
  • 原文地址:https://www.cnblogs.com/bztMinamoto/p/9990137.html
Copyright © 2020-2023  润新知