Snake Charmer

View as PDF

Submit solution

Points: 100
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Snake Charmer

Note 1 - This problem was taken from AIO 2017. Visit orac2.info for more problems (would highly reccomend) Note 2 - While this problem has a fairly simple greedy solution which you can use if you want, there is an alternative solution that is much easier to implement and prove.

Problem Description

You are a snake charmer performing for a travelling circus troupe. Your act is that you can move your snake along the integer points on a grid. Initially, you snake is at point (0,0) and facing up. You can make it do two moves:

An L move: make it turn left and then move forward by one square. An R move: make it turn right and then move forward by one square.

For example, if you start at (0,0) and do:

  • R: Now at point (1,0) facing right
  • L: Now at point (1,1) facing up
  • L: Now at point (0,1) facing left
  • R: Now at point (0,2) facing up
  • L: Now at point (-1, 2) facing left

As you are not paid hourly, you want to do this as quick as possible - What is the shortest sequence of R and L moves by which you can move the snake to the given point?

Sample Input 1

-1 2

Sample Output 1

RLLRL

Sample Explanation 1

In the description of the problem.

Constraints

|x,y| \le 5000


Comments

There are no comments at the moment.