#include <stdio.h> #define MAX 201740 int main() { int C[MAX],i,N,n; for (i = 0; i < MAX; i++) C[i] = 0; scanf("%d",&N); for (n = 0; n < N; n++) { scanf("%d",&i); C[i]++; } n = 0; while (n < MAX) { C[n+1] += C[n] / 2; C[n] %= 2; n++; } while (C[--n] == 0) ; printf("%d\n",n); 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 | #include <stdio.h> #define MAX 201740 int main() { int C[MAX],i,N,n; for (i = 0; i < MAX; i++) C[i] = 0; scanf("%d",&N); for (n = 0; n < N; n++) { scanf("%d",&i); C[i]++; } n = 0; while (n < MAX) { C[n+1] += C[n] / 2; C[n] %= 2; n++; } while (C[--n] == 0) ; printf("%d\n",n); return 0; } |