Advertisement
Pridexs

Regional_Curitiba_Problema_B

Sep 17th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <cctype>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <bitset>
  9. #include <vector>
  10. #include <stack>
  11. #include <queue>
  12. #include <set>
  13. #include <map>
  14.  
  15. /*
  16. 1 2 3 4
  17. 3 1 4 2
  18. 4 3 2 1
  19. 2 4 1 3
  20. 1 2 3 4
  21. */
  22.  
  23. int main() {
  24.  
  25.     int n, pos, cont;
  26.     int metade;
  27.  
  28.     while(scanf("%d", &n) != EOF) {
  29.         cont = 0;
  30.         pos = 1;
  31.         metade = n/2;
  32.         do {
  33.             if (pos <= metade) {
  34.                 pos *= 2;
  35.             } else {
  36.                 pos = (n - ((n-pos+1) * 2)) + 1;
  37.             }
  38.             //printf("%d\n", pos);
  39.             cont++;
  40.         } while(pos != 1);
  41.         printf("%d\n", cont);  
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement