zoukankan      html  css  js  c++  java
  • BZOJ1800: [Ahoi2009]fly 飞行棋

    【传送门:BZOJ1800


    简要题意:

      有一个圆,并且将这个圆分成n段弧,给出n段弧的长度,相邻的弧之间有交点,求出这些点中能围成多少个矩形


    题解:

      O(n4),无脑枚举

      圆内接矩形对角线为直径,并且对边相等,所以对弧相等

      利用这个性质做就可以了,不过要注意细节


    参考代码:

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int a[21];
    bool v[21][21][21][21];
    int main()
    {
        int n;
        scanf("%d",&n);
        a[0]=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            a[i]+=a[i-1];
        }
        if(a[n]%2==1)
        {
            printf("0
    ");return 0;
        }
        int ans=0;
        memset(v,false,sizeof(v));
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                bool b1=false;
                int d1=a[j]-a[i];
                if(d1*2>=a[n]){d1=a[n]-d1;b1=true;}
                if(d1==0) continue;
                for(int x=1;x<=n;x++)
                {
                    if(x!=i&&x!=j)
                    {
                        for(int y=x+1;y<=n;y++)
                        {
                            if(y!=i&&y!=j)
                            {
                                if(v[i][j][x][y]==true) continue;
                                bool b2=false;
                                int d2=a[y]-a[x];
                                if(d2*2>=a[n]){d2=a[n]-d2;b2=true;}
                                if(d1==d2&&b1==b2)
                                {
                                    int t;
                                    if(b1==false&&b2==false) t=a[x]-a[i];
                                    else if(b1==true&&b2==false) t=a[n]-a[y]+a[i];
                                    else if(b1==false&&b2==true) t=a[n]-a[j]+a[x];
                                    else continue;
                                    if(t==a[n]/2)
                                    {
                                        v[i][j][x][y]=true;
                                        v[x][y][i][j]=true;
                                        ans++;
                                    }
                                }
                            }
                        }
                    }
                }
                
            }
        }
        printf("%d
    ",ans);
        return 0;
    } 

     

  • 相关阅读:
    冲刺第五天个人博客
    冲刺第四天个人博客
    典型用户及场景
    冲刺第三天个人博客
    冲刺第二天个人博客
    冲刺第一天个人博客
    第三周学习进度表
    第二周学习进度表
    webServices
    vs开发工具使用问题
  • 原文地址:https://www.cnblogs.com/Never-mind/p/8342335.html
Copyright © 2011-2022 走看看