#include <stdio.h> #include <stdlib.h> #include <math.h> #define max(a, b) a>b?a:b int main() { int n, a, m = -1; const int LEN = 201718; int *tmp = calloc(LEN, sizeof(int)); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a); tmp[a]++; m = max(m, a); } for (int i = 0; i < m; i++) { tmp[i + 1] += tmp[i] / 2; tmp[i] %= 2; } printf("%d\n", m + (int) (log(tmp[m]) / log(2))); 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 | #include <stdio.h> #include <stdlib.h> #include <math.h> #define max(a, b) a>b?a:b int main() { int n, a, m = -1; const int LEN = 201718; int *tmp = calloc(LEN, sizeof(int)); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a); tmp[a]++; m = max(m, a); } for (int i = 0; i < m; i++) { tmp[i + 1] += tmp[i] / 2; tmp[i] %= 2; } printf("%d\n", m + (int) (log(tmp[m]) / log(2))); return 0; } |