FARFROMO - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: notsoloud
Testers: iceknight1093, tabr
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

Given the positions of Alex and Bob on the plane, find out who is standing further away from the origin.

EXPLANATION:

The distance of point (x, y) from the origin is \sqrt{x^2 + y^2}

So, Alex’s distance from Chef is \sqrt{x_1^2 + y_1^2} and Bob’s distance is \sqrt{x_2^2 + y_2^2}.

Compute these two quantities and then compare them to find out whether they’re equal or one is larger than the other.

In order to not deal with floating-point issues, notice that it’s enough to compare (x_1^2+y_1^2) and (x_2^2+y_2^2).

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Code (Python)
for _ in range(int(input())):
    x1, y1, x2, y2 = map(int, input().split())
    d1 = x1**2 + y1**2
    d2 = x2**2 + y2**2
    print('Equal' if d1 == d2 else ('Alex' if d1 > d2 else 'Bob'))