#include <iostream> using namespace std; const int MAX = 201718; int main() { ios_base::sync_with_stdio(false); int n, t; int max = 0; int M[MAX + 100] = { 0 }; cin >> n; while (n--) { cin >> t; if (t > max) max = t; M[t]++; } int curv = 0, a = 0; for (int i = 0; i <= max; i++) { curv /= 2; curv += M[i]; if (curv) a = i; } while (curv /= 2) { a++; } printf("%d\n", a); 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 35 36 37 38 39 40 41 42 | #include <iostream> using namespace std; const int MAX = 201718; int main() { ios_base::sync_with_stdio(false); int n, t; int max = 0; int M[MAX + 100] = { 0 }; cin >> n; while (n--) { cin >> t; if (t > max) max = t; M[t]++; } int curv = 0, a = 0; for (int i = 0; i <= max; i++) { curv /= 2; curv += M[i]; if (curv) a = i; } while (curv /= 2) { a++; } printf("%d\n", a); return 0; } |