• 2019 Multi-University Training Contest 4


    #include<bits/stdc++.h>
    using namespace std;
    const int N=200010;
    int sum,ans[N],base,now,n;
    int main()
    {
        int T;
        scanf("%d",&T);
        while (T--)
        {
            sum=0;
            scanf("%d",&n);
            for (int i=2; i<=n; i++)
            {
                if (i%2==0)
                {
                    ans[i]=1;
                }
                else
                {
                    base=1;
                    now=i;
                    while (now)
                    {
                        if ((now&1)==0)
                        {
                            break;
                        }
                        base<<=1;
                        now>>=1;
                    }
                    if (base>n)
                    {
                        sum++;
                        ans[i]=1;
                    }
                    else
                    {
                        ans[i]=base;
                    }
                }
            }
            printf("%d
    ",sum);
            for (int i=2; i<n; i++)
            {
                printf("%d ",ans[i]);
            }
            printf("%d
    ",ans[n]);
        }
    }
    

     

    #include<bits/stdc++.h>
    using namespace std;
    
    long long n,k,kk,p,a[100010],b[100100][5];
    int main()
    {
        int T;
        scanf("%d",&T);
        while (T--)
        {
            scanf("%lld%lld",&n,&k);
            if (n==1&&k==1)
            {
                puts("yes");
                puts("1");
                continue;
            }
            if ((n*(n+1)/2)%k!=0||n==k)
            {
                puts("no");
                continue;
            }
            puts("yes");
            if ((n/k)%2==0)
            {
                a[1]=1;
                p=k*2-1;
                for (int i=1; i<n/k; i++)
                {
                    if (i&1)
                    {
                        a[i+1]=a[i]+p;
                    }
                    else
                    {
                        a[i+1]=a[i]+1;
                    }
                }
                for (int i=1; i<=k; i++)
                {
                    for (int j=1; j<=n/k; j++)
                    {
                        printf("%lld",a[j]);
                        if (j==n/k)
                        {
                            printf("
    ");
                        }
                        else
                        {
                            printf(" ");
                        }
                        if (j&1)
                        {
                            a[j]++;
                        }
                        else
                        {
                            a[j]--;
                        }
                    }
                }
            }
            else
            {
                b[1][1]=n;
                for (int i=2; i<=k; i++)
                {
                    b[i][1]=n-i+1;
                }
                b[k/2+1][2]=n-k;
                kk=0;
                for (int i=k/2+2; i<=k; i++)
                {
                    kk++;
                    b[i][2]=n-k-kk;
                }
                for (int i=1; i<=k/2; i++)
                {
                    kk++;
                    b[i][2]=n-k-kk;
                }
                b[k/2+1][3]=n-k*3+1;
                kk=0;
                for (int i=k/2+2; i<=k; i++)
                {
                    kk+=2;
                    b[i][3]=n-k*3+1+kk;
                }
                int p=n-k*3+1+kk+1;
                kk=0;
                for (int i=k/2;i>=1; i--)
                {
                    kk+=2;
                    b[i][3]=p-kk;
                }
                a[1]=1;
                p=k*2-1;
                for (int i=1; i<=n/k-3; i++)
                {
                    if (i&1)
                    {
                        a[i+1]=a[i]+p;
                    }
                    else
                    {
                        a[i+1]=a[i]+1;
                    }
                }
                for (int i=1; i<=k; i++)
                {
                    if (n/k-3>=1)
                        for (int j=1; j<=n/k-3; j++)
                        {
                            printf("%lld ",a[j]);
                            if (j&1)
                            {
                                a[j]++;
                            }
                            else
                            {
                                a[j]--;
                            }
                        }
                    for (int j=n/k-2; j<=n/k; j++)
                    {
                        printf("%lld",b[i][j-n/k+3]);
                        if (j==n/k)
                        {
                            printf("
    ");
                        }
                        else
                        {
                            printf(" ");
                        }
                    }
                }
            }
        }
    }

    #include<bits/stdc++.h>
    
    using namespace std;
    
    int a[100],res,k;
    
    int main()
    {
        int T;
        scanf("%d",&T);
        while (T--)
        {
            for (int i=0; i<16; i++)
            {
                scanf("%d",&a[i]);
            }
            res=0;
            for (int i=0; i<16; i++)
            {
                for (int j=i+1; j<16; j++)
                {
                    if (a[i]>0&&a[j]>0&&a[i]>a[j])
                    {
                        res++;
    
                    }
                }
            }
            for (int i=0; i<16; i++)
            {
                if (!a[i])
                {
                    k=i/4;
                    break;
                }
            }
            if (((3-k)%2)==(res%2))
            {
                printf("Yes
    ");
            }
            else
            {
                printf("No
    ");
            }
    
        }
    }
    

      

    #include<bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    ll ans,prime[10010],v[10010],tot,n,k;
    
    void get_prime()
    {
        for (ll i=2; i<=10000; i++)
        {
            if (!v[i])
            {
                prime[tot++]=i;
            }
            for (ll j=0; prime[j]*i<=10000; j++)
            {
                v[prime[j]*i]=1;
                if (i%prime[j]==0)
                {
                    break;
                }
            }
        }
    }
    
    ll check(ll l,ll r,ll n)
    {
        while (l<r)
        {
            ll mid=(l+r)>>1;
            if (mid*mid*mid<n)
            {
                l=mid+1;
            }
            if (mid*mid*mid>n)
            {
                r=mid-1;
            }
            if (mid*mid*mid==n)
            {
                return mid;
            }
        }
        return l;
    }
    int main()
    {
        ll T;
        get_prime();
        scanf("%lld",&T);
        while (T--)
        {
            ans=0x3f3f3f3f;
            scanf("%lld",&n);
            for (ll i=0; i<tot; i++)
            {
                k=0;
                while (n%prime[i]==0)
                {
                    n=n/prime[i];
                    k++;
                }
                if (k) ans=min(ans,k);
            }
            if (n>1)
            {
                ll k2=sqrt(n);
                ll k4=sqrt(k2);
                if (k2*k2==n)
                {
                    if (k4*k4*k4*k4==n)
                    {
                        ans=min(ans,4ll);
                    }
                    else
                    {
                        ans=min(ans,2ll);
                    }
                }
                else
                {
                    ll k3=check(1,1e6,n);
                    if (k3*k3*k3==n) ans=min(ans,3ll);
                    else ans=1;
                }
            }
            printf("%lld
    ",ans);
        }
    }
    

     

    #include <bits/stdc++.h>
    
    using namespace std;
    const int N = 1000001;
    const int maxn=1e6+10;
    const int maxm=maxn*10;
    struct Node
    {
        int val,l,r;
    } node[maxm];
    int tot,root[maxn];
    
    int build(int l,int r)
    {
        int x=++tot;
        if (l<r)
        {
            int mid=(l+r)>>1;
            node[x].l=build(l,mid);
            node[x].r=build(mid+1,r);
        }
        node[x].val=0;
        return x;
    }
    
    int update(int rt,int l,int r,int x,int v)
    {
        node[++tot]=node[rt];
        rt=tot;
        if (l==r)
        {
            node[rt].val+=v;
            return rt;
        }
        else
        {
            int mid=(l+r)>>1;
            if (x<=mid) node[rt].l=update(node[rt].l,l,mid,x,v);
            else
            {
                node[rt].r=update(node[rt].r,mid+1,r,x,v);
            }
            node[rt].val+=v;
            return rt;
        }
    }
    
    int query(int rt1,int rt2,int l,int r,int L,int R)
    {
        if (L<=l&&r<=R)
        {
            return node[rt2].val-node[rt1].val;
        }
        else
        {
            int mid=(l+r)>>1,ans=0;
            if (L<=mid) ans+=query(node[rt1].l,node[rt2].l,l,mid,L,R);
            if (mid<R) ans+=query(node[rt1].r,node[rt2].r,mid+1,r,L,R);
            return ans;
        }
    }
    int a[maxn],n,m,l,r,p,k;
    
    int main()
    {
        int T;
        scanf("%d",&T);
        while (T--)
        {
            scanf("%d%d",&n,&m);
            tot=0;
            root[0]=build(1,N);
            for (int i=1; i<=n; i++)
            {
                scanf("%d",&a[i]);
                root[i]=update(root[i-1],1,N,a[i],1);
            }
            int ans=0;
            while (m--)
            {
                scanf("%d%d%d%d",&l,&r,&p,&k);
                l^=ans;
                r^=ans;
                p^=ans;
                k^=ans;
                if (l>r)
                {
                    swap(l,r);
                }
                int L=0,R=N;
                while (L<R)
                {
                    int mid=(L+R)>>1;
                    int sum=query(root[l-1],root[r],1,N,max(0,p-mid),min(N,p+mid));
                    if (sum<k)
                    {
                        L=mid+1;
                    }
                    else
                    {
                        R=mid;
                    }
                }
                ans=R;
                printf("%d
    ",R);
            }
        }
    }
    

      

  • 相关阅读:
    团队-爬取豆瓣电影TOP250-成员简介及分工
    结对-贪吃蛇游戏-需求分析
    个人编程作业
    团队项目编程作业
    课后作业-阅读任务-阅读提问-1
    团队-爬虫豆瓣电影TOP250-成员简介及分工
    结对-英文词频检测程序-需求分析
    对软件工程课程的期望
    自我介绍
    作业0
  • 原文地址:https://www.cnblogs.com/Accpted/p/11278187.html
Copyright © 2020-2023  润新知