kdzhr

Калькулятор/Жадный

Mar 21st, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. // OK https://informatics.msk.ru/moodle/mod/statements/view3.php?chapterid=113440#1
  2.  
  3. # include <iostream>
  4.  
  5. size_t a_n(size_t n) {
  6.     return n / 2;
  7. }
  8.  
  9. size_t b_n(size_t n) {
  10.     return (n + 1) / 2;
  11. }
  12.  
  13. size_t c_n(size_t n) {
  14.     if (n != 0) {
  15.         return (n - 1) / 2;
  16.     }
  17.     return 0;
  18. }
  19.  
  20. int main() {
  21.     size_t n, a, b, c;
  22.     std::cin >> n >> a >> b >> c;
  23.     while (b-- > 0) {
  24.         n = b_n(n);
  25.     }
  26.     while (a-- > 0) {
  27.         n = a_n(n);
  28.     }
  29.     while (c-- > 0) {
  30.         n = c_n(n);
  31.     }
  32.     std::cout << n;
  33.     return 0;
  34. }
Add Comment
Please, Sign In to add comment