You are not logged in. Please login at www.codechef.com to post your questions!

×

TIMEASR - Editorial

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

This question is marked "community wiki".

asked 04 Oct '15, 04:28

xcwgf666's gravatar image

6★xcwgf666 ♦♦
719436377
accept rate: 0%

edited 15 Jan '16, 13:26

admin's gravatar image

0★admin ♦♦
19.8k350498541


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

link

answered 13 Oct '15, 23:23

aka38's gravatar image

4★aka38
22
accept rate: 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

link

answered 12 Oct '15, 15:25

osho1278's gravatar image

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) atulshanbhag4★

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

link

answered 12 Oct '15, 21:06

mayank_r_b's gravatar image

4★mayank_r_b
723
accept rate: 9%

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

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

answered 12 Oct '15, 23:25

aminoacid's gravatar image

4★aminoacid
212
accept rate: 0%

edited 12 Oct '15, 23:27

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

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

link

answered 12 Oct '15, 23:26

krishnakhowal's gravatar image

2★krishnakhowal
1
accept rate: 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

link

answered 13 Oct '15, 00:27

arpn's gravatar image

4★arpn
464516
accept rate: 29%

check this video editorial : https://www.youtube.com/watch?v=VeESbUgz2fY

link

answered 13 Oct '15, 21:23

ankit15's gravatar image

2★ankit15
412
accept rate: 0%

check this video editorial : https://www.youtube.com/watch?v=VeESbUgz2fY

link

answered 13 Oct '15, 21:24

ankit15's gravatar image

2★ankit15
412
accept rate: 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)

link

answered 19 Oct '15, 14:27

himanshu_9419's gravatar image

4★himanshu_9419
111118
accept rate: 18%

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?

link

answered 28 Oct '15, 01:46

prasadram126's gravatar image

2★prasadram126
121
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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