HDU2511: tower X

Source: Internet
Author: User

Problem Description
1, 2 ,..., n indicates n plates. the number is big. place n plates on 1st columns. the dashboard cannot be placed on a small disk. the plates on the 1st columns are a [1], a [2],..., a [n]. a [1] = n, a [2] = n-1 ,..., a [n] = 1. that is, a [1] is the bottom plate. move n plates to 3rd columns. only one plate can be moved at a time, and the tray cannot be placed on a small disk. ask which plate is moved at MB and which column is moved from. for example, n = 3, m = 2. the answer is: 2 1 2, that is, the disk is moved from 1st to 2nd.

 


Input
The fifth row is an integer T, indicating that there are T groups of data. There are T rows below. Each row has two integers n (1 ≤ n ≤ 63), m ≤ 2 ^ n-1

 


Output
Output The number of plates and the number of columns that move the MB number.

 


Sample Input
4
3 2
4 5
39 183251937942
63 3074457345618258570


Sample Output
2 1 2
1 3 1
2 2 3
2 2 3

First, list the situation and find the rule.

Rule is

If the total number of disks is the same as that of the current number, the order of movement is 1-> 3-> 2-> 1.

Otherwise it is 1-> 2-> 3-> 1

Remember that the moving order is for the same disk.

 

[Cpp] view plaincopyprint? # Include <stdio. h>
 
_ Int64 pow (_ int64 n)
{
_ Int64 s = 1;
Int I;
For (I = 1; I <= n; I ++)
S * = 2;
Return s;
}
 
Int main ()
{
_ Int64 n, m, t;
Int a [3] [2] = {3, 1}, {1, 2}, {2, 3}, B [3] [2] = {2, 1}, {1, 3 }, {3, 2 }};
Int I, test;
Scanf ("% d", & test );
While (test --)
{
_ Int64 cnt = 0;
Scanf ("% I64d % I64d", & n, & m );
_ Int64 tem = m;
For (I = 1; I <= n; I ++)
{
T = m % 2;
If (t)
{
Printf ("% d", I );
Break;
}
Else
M/= 2;
}
If (tem % 2)
Cnt = (tem + 1)/2;
Else
{
M = tem;
_ Int64 sum = pow (I-1 );
M = m-sum;
Cnt = m/pow (I) + 1;
}
Int flag = 0;
If (n % 2 & I % 2) | (n % 2 = 0 & I % 2 = 0 ))
{
Flag = 1;
}
Cnt = cnt % 3;
If (flag)
{
Printf ("% d \ n", B [cnt] [0], B [cnt] [1]);
}
Else
{
Printf ("% d \ n", a [cnt] [0], a [cnt] [1]);
}
}
 
Return 0;
}

# Include <stdio. h>

_ Int64 pow (_ int64 n)
{
_ Int64 s = 1;
Int I;
For (I = 1; I <= n; I ++)
S * = 2;
Return s;
}

Int main ()
{
_ Int64 n, m, t;
Int a [3] [2] = {3, 1}, {1, 2}, {2, 3}, B [3] [2] = {2, 1}, {1, 3 }, {3, 2 }};
Int I, test;
Scanf ("% d", & test );
While (test --)
{
_ Int64 cnt = 0;
Scanf ("% I64d % I64d", & n, & m );
_ Int64 tem = m;
For (I = 1; I <= n; I ++)
{
T = m % 2;
If (t)
{
Printf ("% d", I );
Break;
}
Else
M/= 2;
}
If (tem % 2)
Cnt = (tem + 1)/2;
Else
{
M = tem;
_ Int64 sum = pow (I-1 );
M = m-sum;
Cnt = m/pow (I) + 1;
}
Int flag = 0;
If (n % 2 & I % 2) | (n % 2 = 0 & I % 2 = 0 ))
{
Flag = 1;
}
Cnt = cnt % 3;
If (flag)
{
Printf ("% d \ n", B [cnt] [0], B [cnt] [1]);
}
Else
{
Printf ("% d \ n", a [cnt] [0], a [cnt] [1]);
}
}

Return 0;
}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.