 Simple

# Pre-requisites

Basic programming language constructions

# Problem

Find all times in the HH:MM format, such that the absolute value of the angle between hours’ and minutes’ hands is equal to the given value.

# Explanation

Let us iterate through all possible values of times and check the absolute value of the angle between hours’ and minutes’ hands. This angle is calculated as the difference between two angles, namely, A - the angle of hours’ hand and B - the angle of minutes’ hand.

Let us define the rules for calculating the angles of the hands:

• Every minute hours’ hand moves by 360/(12*60)=1/2 degrees, since 360 degrees is the full circle and in every of 12 hour there are 60 minutes. Every minute the hand shifts by the same angle. So, we get A = N/2, where N is the number of minutes since the beginning of the day (00:00).

• Every minute minutes’ hand moves by 360/60 = 6 degrees. So, B = M*6, where M is the current number of minutes (not taking hours into account).

So, the solution consists of iterating all the possible values of times and checking the corresponding absolute angles. In total there are only 60*12 = 720 possible times.

# Setter’s Solution

Can be found here

# Tester’s Solution

Can be found here

2 Likes

The other way of doing it could be ::

iterate hour from 0 to 6 and minute from 0 to 59 . Total iterations will be 360 and by symmetry calculate the other time by subtraction . exception for 0 degree and 180 degree.

*** i tried the above algorithm (editorial one) in python , but my last case did not pass. I tried the above method too but my last case still shows TLE.

Anyone , let me know if there is anything wrong with my approach.

regards

I did it with graph and precomputation Link to my solution : https://www.codechef.com/viewsolution/8420150 Python(2.7) solution using dictionaries (HASHMAP) Without using PYPY.

https://www.codechef.com/viewsolution/8326513

Can anyone tell me why I got TLE in 3rd Test Case?

My Solution link:
https://www.codechef.com/viewsolution/8391242

Just got the equation from the wikipedia, and implemented it. Starting from 0-719. For me it was the easiest problem in the set :D. I hardly spent any time for that,kinda cute problem. Enjoyed it Here’s my code- https://www.codechef.com/viewsolution/8372841

check this video editorial :

check this video editorial :

I did it though partially(60 pts) using relative angular speed of minute hand w.r.t hour hand .

1 Like

my code is working well for integer angle but generating error for non integer angle at codechef. Please see my code and tell me where I’m wrong.
Solution(code)

Hi can any body please explain how to implement this “a time value is considered valid if the angle between the clock’s hands for that value and the angle Chef’s friend has described differ by less than 1/120 degrees.” i have tried like below

if((inputangle - actualange)<1/120)
print corresponding_time


for input angle 30 i am getting 05:30 and 06:30 so can anybody please tell me how to implement the above condition?

I am not sure but your way of doing might fail because of the 1/120 precision. there might not be 2 times for a given angle because of that. i am not sure of this though.