#include <stdio.h> using namespace std; #define FOR0(i, n) for (int i = 0; i < n; i++) #define FOR1(i, n) for (int i = 1; i < n; i++) #define M 201719 int n; int A[M]; int main() { scanf("%d", &n); int tmp, max = 0; FOR0(i, n) { scanf("%d", &tmp); A[tmp]++; if (max < tmp) max = tmp; } FOR1(i, max + 1) { A[i] += A[i - 1] / 2; } int counter = A[max]; while (counter > 1) { counter /= 2; max++; } printf("%d\n", max); 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 | #include <stdio.h> using namespace std; #define FOR0(i, n) for (int i = 0; i < n; i++) #define FOR1(i, n) for (int i = 1; i < n; i++) #define M 201719 int n; int A[M]; int main() { scanf("%d", &n); int tmp, max = 0; FOR0(i, n) { scanf("%d", &tmp); A[tmp]++; if (max < tmp) max = tmp; } FOR1(i, max + 1) { A[i] += A[i - 1] / 2; } int counter = A[max]; while (counter > 1) { counter /= 2; max++; } printf("%d\n", max); return 0; } |