Codeforces768C-Jon Snow and his Favourite Number-位运算乱搞

(有任何问题欢迎留言或私聊 && 欢迎交流讨论哦

题意:传送门

 原题目描述再最下面。
 n个数,k此操作,每次操作给数组从小到大的第奇数个数异或上x。问k此操作后,数组的最大值的最小值是多少?

思路:

 神奇的瞎搞题。据说根据异或运算的性质,若干次操作后会形成一个稳定的数组。
 所以暴力枚举加特判即可。

AC代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <bitset>
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long LL;
const int N = 1e6 + 7;
const int INF = 0x3f3f3f3f;
int n, k, x;
int ar[N], amax[N], amin[N];
int main(int argc, char const *argv[]){
  while(~scanf("%d%d%d", &n, &k, &x)){
    for(int i = 0; i < n; ++i){
      scanf("%d", &ar[i]);
    }
    sort(ar, ar+n);
    for(int t = 0; t < k; ++t){
      for(int i = 0; i < n; ++i){
        if(!(i&1)){
          ar[i] ^= x;
        }
      }
      sort(ar, ar+n);
      amax[t] = ar[n-1];
      amin[t] = ar[0];
      if(t>=2&&amax[t]==amax[t-1]&&amax[t]==amax[t-2]&&amin[t]==amin[t-1]&&amin[t]==amin[t-2])break;
    }
    printf("%d %d\n", ar[n-1], ar[0]);
  }
  return 0;
}


原题目描述:

这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_39599067/article/details/81129790