首页 > 代码库 > 2016级萌新选拔赛BE题

2016级萌新选拔赛BE题

#include<bits/stdc++.h>
using namespace std;
#define  ll long long
ll a[200000];
ll d[200000];

int main()
{
    ll n;
    ll sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=0;i<n-1;i++)
    {
        d[i]=a[i+1]-a[i];
    }
    d[n-1]=a[0]-a[n-1];
    if(sum%(n*(n+1)/2)==0)
    {
        ll k=sum/(n*(n+1)/2);
        for(int i=0;i<n;i++)
        {
            if((k-(d[i]))%n||k-d[i]<0)
            {
                cout<<"NO"<<endl;
                return 0;
            }
        }
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
}
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
 
using namespace std;
int a[100];
 
int main()
{
   // freopen("in.txt","r",stdin);
  //  freopen("out.txt","w",stdout);
    int n,m,k;
    while(~scanf("%d%d%d",&n,&k,&m))
    {
        int ans=0;
        for(int i=0; i<(1<<n); ++i)
        {
            int cnt=0;
            memset(a,0,sizeof(a));
            int num=i;
            while(num!=0)
            {
                a[cnt++]=num%2;
                num=num/2;
            }
            int count=0;
            num=1;
            bool f=true;
            for(int j=0; j<cnt; ++j)
            {
                if(a[j]==1)
                {
                    if(num<m&&j!=0)
                        f=false;
                    count++;
                    num=1;
                }
                else
                    num++;
            }
            if(f&&count>=k)
                ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

2016级萌新选拔赛BE题