Uva 679

  1. #include <iostream>
  2. using namespace std;
  3. unsigned int reversebit (int iNumber, int iDepth )
  4.     {
  5.     unsigned int iTar = 0;
  6.     while ( iDepth-- ) 
  7.         {  
  8.         iTar = iTar << 1;  // left shift;
  9.         iTar = iTar | (iNumber & 1);  // put iNumbers' last digit to iTar  
  10.         iNumber = iNumber >> 1;    // remove last digit
  11.         }
  12.     return iTar;   
  13.     }
  14. int main()
  15. {
  16. int iTestC, iD, iI;
  17. int i,j, iTemp;
  18. cin >> iTestC;
  19. while ( iTestC )   
  20.     {
  21.     cin >> iD >> iI;
  22.     cout << reversebit ((iI+iI-1),(iD))  << endl;
  23.     iTestC--;  
  24.     }
  25. }

參考 http://naivered.github.io/2016/03/19/Problem_Solving/UVa/UVa-679-Dropping-Balls/

留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year