Learning With Clock Problem Description Deva recently learned about angles in his…
- User
Learning With Clock Problem Description Deva recently learned about angles in his mathematics class and is eager to explore them further! He began learning about angles using a wall clock.
He chose an ancient wall clock for his learning. This clock has only two hands: the hour hand and the minute hand. The hour hand moves to the next hour only after the minute hand completes a full rotation, staying at the current hour until then. The task is to form a given angle between the two hands of the clock. The rules for forming the given angle are as follows -
Starting from the given position, you can move both hands, but in opposite directions without crossing each other. For example, if you move the hour hand clockwise, you must move the minute hand counterclockwise, and vice versa, without them crossing over each other. The hour hand can only be moved from one hour to the next or previous hour; it cannot be positioned between the hours. However, there are no such restrictions for the minute hand. There is a cost attached to moving either the hour hand or minute hand. Likewise, the direction in which each of them is moved also has different costs attached to it as follows. The cost of moving a hand clockwise incurs cost of A rupees The cost of moving a hand anti-clockwise incurs cost of B rupees. The cost of moving hour hand is X rupees The cost of moving minutes hand is Y rupees. All costs are for per degree. You can form the given angle in any direction i.e. it can either be exterior angle or interior angle. Refer figures in example below for better understanding. For example, if the time is 12:15 and one needs to form an angle of 300 degrees, one can achieve this by moving the minute hand 30 degrees in anti-clockwise direction (i.e., from the 3 to the 2), if the resulting cost is low, as shown in Figure 2 below. com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@67af833b:image1.png
Fig. 1
com.tcs.cv.automata.ei.middleware.DocxToHtmlConverter@67af833b:image2.png
Fig.2
Given the initial time, an integer Q representing the number of queries, and four integers A, B, X, and Y as defined above, an angle will be provided in each query that one needs to form between the hands of the clock. For each query, determine the minimum cost required to form the specified angle and print the total minimum cost as the output.
Constraints 0 <= Angle <= 360 degrees and Angle will be an integer
1 <= A, B, X and Y <= 10
A, B, X and Y are unique.
1 <= Q <=20
Input The first line contains the initial time in the format hours:minutes.
The second line contains an integer Q, representing the number of queries.
The third line contains four space delimited integers A, B, X, and Y respectively, as defined above.
The next Q lines each contain a single integer, representing the angle that you need to form between the hands of the clock.
Output A single integer representing the sum of minimum cost for processing each query.
- Assistant