×

# ZUBREACH - Editorial

Practice

Author: Kazi Hasan Zubaer

Editorialist: Bhavya Agarwal

CAKEWALK

Math

# PROBLEM:

The aim is to find the final position with the information about his movements.

# EXPLANATION:

As mentioned in the problem the initially the person is at the origin and the information about his movements is given in the form of :

U - Up
D - Down
R - Right
L - Left


Or, more clearly

U indicates a move that increases position along y-axis by 1
D indicates a move that decreases position along y-axis by 1
R indicates a move that increases position along x-axis by 1
L indicates a move that decreases position along x-axis by 1


So, first we need to declare two variables px and py to track the movement of the person in x-axis and y-axis respectively axis and assign them to 0 as initial position is 0. With the given constraints they can be int.

px = 0;
py = 0;


Then for the length of movement, l and a character x.

    for i = 1 to l do
if (x = U) then
py = py + 1
if (x = D) then
py = py - 1
if (x = R)
px = px + 1
if (x = L)
px = px - 1


After calculating the final position we need to find at which part the person is that is at

Relative's Position(rx, ry)

Dangerous Position(x, y) where x > m or x < 0 or y > n or y < 0

Somewhere(x, y) where 0 ≤ x ≤ m and 0 ≤ y ≤ n

Since we also need to output the no. of case we can initialize a variable i to 1 and increment it after every test case.

# EDITORIALIST'S SOLUTION:

Can be found here.

This question is marked "community wiki".

563
accept rate: 42%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,852
×1,688
×890

question asked: 25 Feb '18, 16:33

question was seen: 104 times

last updated: 25 Feb '18, 16:46