EZPZ - Editorial

Contest
Practice

Difficulty: Cakewalk

Pre-requisite Knowledge: Loops

Time Complexity:   (O(N)) for each test case.

Problem:

You are given an integer N denoting the number of vertices of a regular polygon. Also, you are given two integers A and B denoting vertex numbers. You need to find the smallest vertex X for which the sum of the minimum distance of X from A and minimum distance of X from B is minimum.

Quick Explanation:

Run a loop from 1 to N and for each vertex (not A or B) calculate the sum of minimum distance of that vertex from A and B, and update the answer accordingly.

Detailed Explanation:

The minimum distance between two vertices P and Q on a regular polygon can be given as min(abs(Q-P), abs(N-Q+P)).

Run a loop from 1 to N and for each vertex (not A or B) calculate the sum of minimum distance of that vertex from A and B, and update the answer accordingly.

Solution Links:

Author's Solution