• 【codeforces 768C】Jon Snow and his Favourite Number


    【题目链接】:http://codeforces.com/contest/768/problem/C

    【题意】

    给你n个数字;
    让你每次把这n个数字排序;
    然后对奇数位的数字进行异或操作,然后对新生成的序列再重复上述操作总共k次;
    问最后的序列的最小值和最大值分别是多少;

    【题解】

    可以用计数排序来搞;
    因为数字最大为1000;
    所以将近O(K*1000)的复杂度;
    完全可以的;
    每次从小到大(0到1000(枚举数字;
    然后根据该数字的个数判断该数字有几个数字要进行异或,几个数字保持原样.
    然后在新的计数排序数组里面记录一下就好;
    最后一遍循环搞出最大最小值就好;

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%lld",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 1e3+500;
    
    int n,k,xx;
    int bo[2][N];
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        rei(n),rei(k),rei(xx);
        rep1(i,1,n)
        {
            int y;
            rei(y);
            bo[0][y]++;
        }
        int now = 0;
        rep1(i,1,k)
        {
            rep1(j,0,1100)
                bo[1-now][j] = 0;
            int x = 0;
            rep1(j,0,1100)
                if (bo[now][j]>0)
                {
                    int ju = bo[now][j]&1;
                    if (x==0)
                    {
                        if (ju)
                        {
                            bo[1-now][j^xx]+=((bo[now][j]+1)/2);
                            bo[1-now][j]+=(bo[now][j]-((bo[now][j]+1)/2));
                            x = 1;
                        }
                        else
                        {
                            bo[1-now][j^xx]+=bo[now][j]/2;
                            bo[1-now][j]+=(bo[now][j]-(bo[now][j]/2));
                            x = 0;
                        }
                    }
                    else
                    {
                        if (ju)
                        {
                            bo[1-now][j^xx]+=((bo[now][j]-1)/2);
                            bo[1-now][j]+=(bo[now][j]-((bo[now][j]-1)/2));
                            x = 0;
                        }
                        else
                        {
                            bo[1-now][j^xx]+=((bo[now][j])/2);
                            bo[1-now][j]+=(bo[now][j]-((bo[now][j])/2));
                            x = 1;
                        }
                    }
                }
            now = 1-now;
        }
        rep2(i,1100,0)
            if (bo[now][i]>0)
            {
                printf("%d ",i);
                break;
            }
        rep1(i,0,1100)
            if (bo[now][i]>0)
            {
                printf("%d
    ",i);
                break;
            }
        return 0;
    }
  • 相关阅读:
    POJ3164 Command Network
    UVa11401 Triangle Counting
    UVa11174 Stand in a Line
    UVa11806 Cheerleaders
    Uva11538 Chess Queen
    Bzoj3130 [Sdoi2013]费用流
    Bzoj3262 陌上花开
    模拟25A 题解
    模拟24 题解
    模拟23 题解
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626607.html
Copyright © 2020-2023  润新知