×

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

This question is marked "community wiki".

719436377
accept rate: 0%

19.8k350498541

 1 I did it though partially(60 pts) using relative angular speed of minute hand w.r.t hour hand . answered 13 Oct '15, 23:23 4★aka38 2●2 accept rate: 0%
 0 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 answered 12 Oct '15, 15:25 1★osho1278 1 accept rate: 0% 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. (12 Oct '15, 15:29)
 0 I did it with graph and precomputation :D Link to my solution : https://www.codechef.com/viewsolution/8420150 ;) answered 12 Oct '15, 21:06 72●3 accept rate: 9%
 0 Python(2.7) solution using dictionaries (HASHMAP) :) Without using PYPY. https://www.codechef.com/viewsolution/8326513  answered 12 Oct '15, 23:25 21●2 accept rate: 0%
 0 Can anyone tell me why I got TLE in 3rd Test Case? My Solution link: https://www.codechef.com/viewsolution/8391242 answered 12 Oct '15, 23:26 1 accept rate: 0%
 0 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 :P Here's my code- https://www.codechef.com/viewsolution/8372841 answered 13 Oct '15, 00:27 4★arpn 464●5●16 accept rate: 29%
 0 answered 13 Oct '15, 00:57 11 accept rate: 0%
 0 check this video editorial : https://www.youtube.com/watch?v=VeESbUgz2fY answered 13 Oct '15, 21:23 2★ankit15 41●2 accept rate: 0%
 0 check this video editorial : https://www.youtube.com/watch?v=VeESbUgz2fY answered 13 Oct '15, 21:24 2★ankit15 41●2 accept rate: 0%
 0 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) answered 19 Oct '15, 14:27 111●1●1●8 accept rate: 18%
 0 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? answered 28 Oct '15, 01:46 12●1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,852
×1,191
×968
×103

question asked: 04 Oct '15, 04:28

question was seen: 4,573 times

last updated: 15 Jan '16, 13:26