#include <stdio.h> int main() { const int MAX_DELTA = 20; const int MAX_NOMINAL = 201718 + MAX_DELTA; int n; int nominals[MAX_NOMINAL + 1] = {}; int max_nominal = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { int a; scanf("%d", &a); nominals[a]++; } for (int i = 0; i < MAX_NOMINAL + 1; i++) { int power = 1; if (nominals[i] & 1) { max_nominal = i; } nominals[i] >>= 1; while (nominals[i]) { if (nominals[i] & 1) { nominals[i + power]++; } nominals[i] >>= 1; power++; } } printf("%d", max_nominal); 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 | #include <stdio.h> int main() { const int MAX_DELTA = 20; const int MAX_NOMINAL = 201718 + MAX_DELTA; int n; int nominals[MAX_NOMINAL + 1] = {}; int max_nominal = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { int a; scanf("%d", &a); nominals[a]++; } for (int i = 0; i < MAX_NOMINAL + 1; i++) { int power = 1; if (nominals[i] & 1) { max_nominal = i; } nominals[i] >>= 1; while (nominals[i]) { if (nominals[i] & 1) { nominals[i + power]++; } nominals[i] >>= 1; power++; } } printf("%d", max_nominal); return 0; }; |