#include<iostream> #include<cstdio> #include<cmath> using namespace std; int main() { int n; cin >> n; int size = 201718; int * array = new int [size+1](); //cout << "przeszlo\n"; getchar(); for (int i=0; i<n; i++){ char c = '0'; int c_number = 0; int x = 0; do{ c_number = (int)c - 48; x = x*10 + c_number; c = getchar(); }while(c >= 48 && c < 58); //cout << "znalazlem: " << x << "\n"; ++array[x]; } int max_no_zero = 0; for(int i=0; i<size; i++){ array[i+1] += (array[i] / 2); if (array[i+1] > 0){ max_no_zero = i+1; } } int k = max_no_zero; int counter = array[max_no_zero]; while(counter > 1){ counter /= 2; ++k; } cout << k << "\n"; delete[] array; 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 43 44 45 46 47 48 49 | #include<iostream> #include<cstdio> #include<cmath> using namespace std; int main() { int n; cin >> n; int size = 201718; int * array = new int [size+1](); //cout << "przeszlo\n"; getchar(); for (int i=0; i<n; i++){ char c = '0'; int c_number = 0; int x = 0; do{ c_number = (int)c - 48; x = x*10 + c_number; c = getchar(); }while(c >= 48 && c < 58); //cout << "znalazlem: " << x << "\n"; ++array[x]; } int max_no_zero = 0; for(int i=0; i<size; i++){ array[i+1] += (array[i] / 2); if (array[i+1] > 0){ max_no_zero = i+1; } } int k = max_no_zero; int counter = array[max_no_zero]; while(counter > 1){ counter /= 2; ++k; } cout << k << "\n"; delete[] array; return 0; } |