#include <bits/stdc++.h> using namespace std; #define MAX 201750 static uint32_t a[MAX]; int main() { uint32_t n, x, amax = 0; scanf("%u", &n); for (uint32_t i = 0; i < n; ++i) { scanf("%u", &x); amax = std::max(amax, x); a[x]++; } for (uint32_t i = 0; i < amax; ++i) { a[i+1] += a[i] / 2; a[i] %= 2; } x = a[amax]; while(x > 1) { x /= 2; amax++; } printf("%u\n", amax); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include <bits/stdc++.h> using namespace std; #define MAX 201750 static uint32_t a[MAX]; int main() { uint32_t n, x, amax = 0; scanf("%u", &n); for (uint32_t i = 0; i < n; ++i) { scanf("%u", &x); amax = std::max(amax, x); a[x]++; } for (uint32_t i = 0; i < amax; ++i) { a[i+1] += a[i] / 2; a[i] %= 2; } x = a[amax]; while(x > 1) { x /= 2; amax++; } printf("%u\n", amax); return 0; } |