TIMEASR - Editorial

ad-hoc
editorial
oct15
simple

#1

Problem Link

Practice

Contest

Difficulty

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

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


#3

I did it with graph and precomputation :smiley:
Link to my solution : https://www.codechef.com/viewsolution/8420150 :wink:


#4

Python(2.7) solution using dictionaries (HASHMAP) :slight_smile:
Without using PYPY.

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

#5

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

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


#6

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 :stuck_out_tongue:

Here’s my code- https://www.codechef.com/viewsolution/8372841


#7

#8

check this video editorial :


#9

check this video editorial :


#10

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


#11

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)


#12

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?


#13

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.