2020 cattle off winter training camp 2 I algorithm foundation built channel title

Cattle customer network link: https://ac.nowcoder.com/acm/contest/3003/I

 

 

 

 

 Solution: At first glance the minimum spanning tree, and then calculate the time complexity of a wave timeout ... (complete tournament chiefs say the minimum spanning tree can live ......)

Put about official explanations:

tai 6 le 

#include <cstdio>
#include <algorithm>
#include <cassert>
using namespace std;
const int N = 2e5 + 5;
int n, k;
int v[N], va, vo, ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &v[i]);
  sort(v + 1, v + n + 1);
  va = 0x7fffffff;
  for (int i = 1; i <= n; i++) {
    va &= v[i];
    vo |= v[i];
  }
  v[n + 1] = 2e9;
  for (int i = n; i; i--)
    k += (v[i] != v[i + 1]);
  va ^= vo;
  for (int i = 0; i <= 30; i++) {
    int cur = 1 << i;
    if (va & cur) {
      ans = cur * (k - 1);
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}

 

Guess you like

Origin www.cnblogs.com/RE-TLE/p/12274056.html