#P1269. [ICPC2017 ASIA Daejeon]Philosopher’s Walk
[ICPC2017 ASIA Daejeon]Philosopher’s Walk
题目描述
In Programming Land, there are several pathways called Philosopher’s Walks for philosophers to have a rest. A Philosopher’s Walk is a pathway in a square_x0002_shaped region with plenty of woods. The woods are helpful for philosophers to think, but they planted so densely like a maze that they lost their ways in the maze of woods of a Philosopher’s Walk. Fortunately, the structures of all Philosopher’s Walks are similar; the structure of a Philosopher’s Walk is designed and constructed according to the same rule in a meter square. The rule for designing the pathway is to take a right-turn in 90 degrees after every 1-meter step when is 1,and the bigger one for which the integer is greater than 1 is built up using four sub-pathways with in a fractal style. Figure F.1 shows three Philosopher’s Walks for which ݇ is 1, 2, and 3. The Philosopher’s Walk consists of four structures with the lower-left and the lower-right ones are 90 degree rotated clockwise and counter-clockwise, respectively; the upper ones have the same structure with .The same is true for any for which the integer is greater than 1. This rule has been devised by a mathematical philosopher David Hilbert (1862 – 1943), and the resulting pathway is usually called a HILBERT CURVE named after him. He once talked about a space filling method using this kind of curve to fill up a square with sides,and every Philosophers’ Walk is designed according to this method. Tae-Cheon is in charge of the rescue of the philosophers lost in Philosopher’s Walks using a hot air balloon. Fortunately, every lost philosopher can report Tae-Cheon the number of meter steps he has taken, and Tae_x0002_Cheon knows the length of a side of the square of the Philosopher’s Walk. He has to identify the location of the lost philosopher, the coordinates assuming that the Philosopher’s Walk is placed in the quadrant of a Cartesian plain with one meter unit length. Assume that the coordinate of the lower-left corner block is . The entrance of a Philosopher’s Walk is always at and the exit is always where is the length of a side. Also assume that the philosopher have walked one meter step when he is in the entrance, and that he always go forward to the exit without back steps.
For example, if the number of meter-steps taken by a lost philosopher in the Philosopher’s Walk in in Figure F.1(b) is 10, your program should report (3, 4).
Your mission is to write a program to help Tae-Cheon by making a program reporting the location of the lost philosopher given the number of meter-steps he has taken and the length of a side of the square of the Philosopher’s Walk. Hurry! A philosopher urgently needs your help.
输入格式
Your program is to read from standard input. The input consists of a single line containing two positive integers, and ,representing the length of a side of the square of the Philosopher’s Walk and the number of meter-steps taken by the lost philosopher, respectively, where and for an integer satisfying .
输出格式
Your program is to write to standard output. The single output line should contain two integers, and ,separated by a space, where is the location of the lost philosopher in the given Philosopher’s Walk.
The following shows sample input and output for two test cases.
样例
4 10
3 4
8 19
2 6