zoukankan      html  css  js  c++  java
  • CodeForces

    https://vjudge.net/problem/CodeForces-768C

    题意:n个数,k次操作,x。每次操作先排序,再让奇数位置上的数据a[i]:=a[i] XOR x;   k<1e5,x<1e5,a[i]<1e3.

    题解:由于每个数据为1~1000,且每次操作先排序,所以可以用桶排序维护所有数据。然后模拟操作(我自己模拟的一直wa,换了另一种才ac)。

      网上另外也有人k%=64 然后暴力ac了,还有找循环节的也ac 了。

    坑:第一次看codeforce 的数据,结果output answer看反了,用错误数据调试。

      ^x的过程中可能产生0,所以每个循环i=0开始。

      i=maxn;while(--i)if(a[i]){cout<<i;break;}这句代码如果最大值是0不会输出。

      做了好久。。。

    ac代码:

    #define _CRT_SECURE_NO_WARNINGS
    #include<iostream>
    #include<string>
    #include<string.h>
    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    const int maxn = 1025;
    int a[maxn],a1[maxn];
    
    int main() {
        
        int n, k, x;
        cin >> n >> k >> x;
        int q;
        for (int i = 1; i <= n; i++)scanf("%d", &q), a[q]++;
        
        while (k--) {
            bool odd = 1;
            memset(a1, 0, sizeof(a1));
            /*for (int i = 1; i <= maxn; i++) if (a[i]) {
                //if(a[i]==1)i
                int t;
                if (a[i] % 2) {
                    if (odd)
                         t= (a[i] + 1) / 2, a[i] = (a[i] - t), a1[i^x]+=t;
                    else t = a[i] / 2, a[i] = (a[i] - t), a1[i^x]+=t;
                    odd = !odd;
                }
                else {
                    a[i] = a[i] / 2; a1[i^x] += a[i];
                }
            }
            for (int i = 1; i <= maxn; i++) a[i] += a1[i];
    
        }*/
            int sum = 0;
            for (int i = 0; i <= maxn; i++) {
                if (sum & 1) {
                    a1[i] += (a[i] + 1) >> 1;
                    a1[i^x] += a[i] >> 1;
                }
                else {
                    a1[i] += a[i] >> 1;
                    a1[i^x] += (a[i] + 1) >> 1;
                }
                sum += a[i];
                
            }
            for (int i = 0; i <= maxn; i++) a[i] = a1[i];
        }
        int i = maxn;
        for (int i = maxn; i >= 0; i--) if (a[i]) {
            cout << i << ' ';
            break;
        }
        for (int i = 0; i <= maxn; i++) if(a[i]){
            cout << i;
            break;
        }
        cin >> n;
    /*    cout << endl;
        for (int i = 1; i <= maxn; i++) if (a[i]) {
            //while(a[i]--)cout << i<<' ';
            cout << a[i] << '*' << i << ' ';
            //break;
        }
        cin >> n;*/
    }
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    对拍
    311随笔
    精彩才刚刚开始
    做不下去了,就开心一下吧。
    情书
    论Sue这个人呐(=@__@=)
    P1113 杂务
    P1546 最短网络 Agri-Net
    P2009 跑步
    P2814 家谱
  • 原文地址:https://www.cnblogs.com/SuuT/p/8516671.html
Copyright © 2011-2022 走看看