号码锁 Combination Lock

2020-09-28 10:17:39 浏览数 (1)

P2693 [USACO1.3]号码锁 Combination Lock

分析:类似约瑟夫环问题,大模拟即可,数据规模小可用o(n^3)100*100*100水过

代码有点硬核,,,,

代码语言:javascript复制
#include<bits/stdc  .h>
using namespace std;
int n,a,b,c,d,e,f;
int flag[10],cnt;
int main()
{
    cin>>n>>a>>b>>c>>d>>e>>f;
    for(int i=1;i<=n;i  )
    {
        for(int j=1;j<=n;j  )
        {
            for(int k=1;k<=n;k  )
            {
                int a1=0,a2=0;
               if((abs(i-a)<=2||(abs(i-a)>=n-2&&abs(i-a)<=n-1))&&(abs(j-b)<=2||(abs(j-b)>=n-2&&abs(j-b)<=n-1))&&(abs(k-c)<=2||(abs(k-c)>=n-2&&abs(k-c)<=n-1)))a1=1;
                if((abs(i-d)<=2||(abs(i-d)>=n-2&&abs(i-d)<=n-1))&&(abs(j-e)<=2||(abs(j-e)>=n-2&&abs(j-e)<=n-1))&&(abs(k-f)<=2||(abs(k-f)>=n-2&&abs(k-f)<=n-1)))a2=1;
               if(a1||a2)
               {
                   cnt  ;
               //cout<<i<<j<<k<<endl;
               }
            }
        }
    }
    cout<<cnt;
    return 0;

}

0 人点赞