#include <iostream> #include <set> #include <vector> //#include <conio.h> #define UI unsigned int struct coin { UI amount; UI value; coin(UI a=0, UI b=0) : amount(a), value(b) {}; }; int main() { UI n; std::cin >> n; //pobranie ilości monet std::multiset<UI> coins; //monety //pobranie wszystkich wartości for (UI i = 0; i < n; i++) { UI tmp; std::cin >> tmp; coins.insert(tmp); } //przypisanie std::vector<UI> money; money.resize(*(coins.rbegin())); for (UI v : coins) money[v-1]++; UI size = *(coins.rbegin()); coins.clear(); for (UI i = 0; i < size - 1; i++) { if (money[i] > 1) money[i + 1] += (money[i] / 2); } coin max(money[size -1], size); while (max.amount > 1) { max.value++; max.amount /= 2; } //for (auto v : money) // std::cout << v << ' '; std::cout << max.value; //_getch(); 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 50 51 52 53 54 55 56 57 58 59 | #include <iostream> #include <set> #include <vector> //#include <conio.h> #define UI unsigned int struct coin { UI amount; UI value; coin(UI a=0, UI b=0) : amount(a), value(b) {}; }; int main() { UI n; std::cin >> n; //pobranie ilości monet std::multiset<UI> coins; //monety //pobranie wszystkich wartości for (UI i = 0; i < n; i++) { UI tmp; std::cin >> tmp; coins.insert(tmp); } //przypisanie std::vector<UI> money; money.resize(*(coins.rbegin())); for (UI v : coins) money[v-1]++; UI size = *(coins.rbegin()); coins.clear(); for (UI i = 0; i < size - 1; i++) { if (money[i] > 1) money[i + 1] += (money[i] / 2); } coin max(money[size -1], size); while (max.amount > 1) { max.value++; max.amount /= 2; } //for (auto v : money) // std::cout << v << ' '; std::cout << max.value; //_getch(); return 0; } |