Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

ANUDTC - Editorial

$
0
0

PROBLEM LINK:

Practice
Contest

Author:Anudeep Nekkanti
Tester:Gerald Agapov
Editorialist:Praveen Dhinwa

DIFFICULTY:

CAKEWALK

PREREQUISITES:

AD-HOC

PROBLEM:

Given a circle, you can make cuts at positive integered angles intersecting at origin. You are given 3 type of questions to answer.

  1. Is it possible to make N equal pieces? You have to use the complete cake.
  2. Is it possible to make N pieces?
  3. Is it possible to make N pieces, such that no two of them are equal?

QUICK EXPLANATION

  1. Check if 360 % N = 0 or not.
  2. Check if N < = 360 or not.
  3. Check if (N * (N + 1)) / 2 < = 360 or not.

EXPLANATION

  1. Note that we are going to make a cut only of positive integered angle. For piceces to be of equal sizes, all the angles of the cuts should be equal. As we know that angle subtended at the centre of the circle is 360'. If we want to partition 360' into N equal parts, then 360 should be divisible by N. Hence we just have to check the condition whether 360 % N = 0 or not ?

  2. Maximum number of pieces we can make are 360 (chose the angle = 1). So if we need to find whether we can make N pieces, we just need to check whether N is less or equal to 360 or not. If yes, then we can make N pieces otherwise we can not.

  3. If want to make N pieces, such that no two of them are equal. Then we can make them in order 1, 2, 3, 4, , N. Sum of the sequence upto N terms will be (N * (N + 1)) / 2. Hence if sum of the sequence is going to be less or equal to 360, then we are surely going to make N distinct pieces. (pieces will have angles 1, 2, upto N). Otherwise we can not.

Strategy of making distinct angles:
Assume that you are able to make n distinct pieces i.e. n * (n + 1) / 2 <= 360. Here is the actual strategy of making the cuts. You can make angles starting from 1, 2, 3 like this. If you have to make n pieces and you have already made n - 1 cuts, the remaining angle itself will be greater than n - 1.

Complexity: O(1). All we need to do is constant number of multiplications and divisions. Hence time complexity is constant or O(1).

AUTHOR'S, TESTER'S AND EDITORIALIST's SOLUTIONS:

Author's solution
Tester's solution
Editorialists's solution


Viewing all articles
Browse latest Browse all 39796

Trending Articles