Nine
Time limit1sMemory limit128 MB
For each desired microwave time, pick the four-digit MM:SS entry with the most 9s, then the least error under 10%, then lexicographically smallest.
- Level
Medium4 of 10
- Topics
- Brute force, Implementation, Simulation, Sorting
- Solved
- No attempts yet
Problem
Randall Munroe of xkcd.com observed that 9 is the most rarely used key on a microwave keypad. Let's spread the load.
A microwave time is entered as four digit keys, displayed as MM:SS. The first two digits are the minutes field and the last two are the seconds field; each field may take any value from 00 to 99 (so the seconds field is allowed to exceed 59). The time in seconds represented by an entry MM:SS is .
Given a desired cooking time (in seconds), find the four-key entry whose represented time uses as many 9 keys as possible while keeping the error below 10%. Formally, an entry is allowed only when
Among all allowed entries, choose the one that uses the greatest number of 9 digits. Break ties by the smallest error , and break any remaining ties by choosing the lexicographically smallest MM:SS string.
Worked example: for 01:15 (that is, seconds), every time from to seconds has less than 10% error. Among those, 00:69, 00:79, 01:09, and 01:19 use the most 9 keys (one each). The ones with the smallest error are 00:79 and 01:19 (error ), and the lexicographically smaller of those is 00:79.
Input
The input contains several test cases. Each line holds one desired cooking time in MM:SS format, where every digit is between 0 and 9. The line 00:00 marks the end of the input and is not processed.
Output
For each test case, print on its own line the four keys to press, in MM:SS format.