2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)

点击打开链接

A.水题

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
int main()
{
    LL a[20];
    for(int i=1;i<=15;i++)
    {
        a[i]=1;
        for(int j=1;j<=i;j++)
            a[i]*=i;
        //cout<<a[i]<<endl;
    }
    LL k;
    while(scanf("%lld",&k)==1)
    {
        int ans=0;
        for(int i=1;i<=15;i++)
            if(k>=a[i]) ans++;
            else break;
        printf("%d\n",ans);
    }
    return 0;
}

E.前后缀+位运算

#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int main()
{
    int n,q;
    while(scanf("%d%d",&n,&q)==2)
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        int x[maxn],y[maxn],z[maxn];
        int x2[maxn],y2[maxn],z2[maxn];
        x[1]=y[1]=z[1]=a[1];
        x2[n]=y2[n]=z2[n]=a[n];
        for(int i=2;i<=n;i++)
        {
            x[i]=x[i-1] & a[i];
            y[i]=y[i-1] | a[i];
            z[i]=z[i-1] ^ a[i];
        }
        for(int i=n-1;i>=1;i--)
        {
            x2[i]=x2[i+1] & a[i];
            y2[i]=y2[i+1] | a[i];
            z2[i]=z2[i+1] ^ a[i];
        }
        while(q--)
        {
            int p;
            scanf("%d",&p);
            if(p==1) printf("%d %d %d\n",x2[2],y2[2],z2[2]);
            else if(p==n) printf("%d %d %d\n",x[n-1],y[n-1],z[n-1]);
                    else printf("%d %d %d\n",x[p-1] & x2[p+1],y[p-1] | y2[p+1],z[p-1] ^ z2[p+1]);
        }
    }
    return 0;
}

G.贪心

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e6+5;
int done[maxn];
int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        memset(done,0,sizeof(done));
        for(int i=0;i<n;i++)
        {
            int k;
            scanf("%d",&k);
            done[k]++;
        }
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            ans+=(done[i]/2);
            done[i]%=2;
            if(i+1<n) {
                if(done[i]&&done[i+1]%2&&done[i+2])
                {
                    ans++;
                    done[i]--;
                    done[i+1]--;
                    done[i+2]--;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

H.数学题+推公式

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
LL pow_mod(LL a,LL b,LL MOD)
{
    LL ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%MOD;
        b>>=1,a=a*a%MOD;
    }
    return ans;
}
int main()
{
    LL n,a;
    while(scanf("%lld%lld",&n,&a)==2)
    {
        LL MOD=1<<n,pos=ceil((double)n/a);
        if(a&1) printf("1\n");
        else {
            //b<n
            LL ans=0;
            for(int i=1;i<=n;i++)
                if(pow_mod(a,i,MOD)==pow_mod(i,a,MOD)) ans++;
            //b>n    xa>=n
            LL res,p=1<<pos;
            res=MOD/p-n/p;
            ans+=res;
            printf("%lld\n",ans);
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_37428263/article/details/81050919