CF1493B.Planet Lapituletti
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts h hours and each hour lasts m minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the number of hours in decimal is displayed first, then (after the colon) follows the number of minutes in decimal; the number of minutes and hours is written with leading zeros if needed to form a two-digit number). Hours are numbered from 0 to h−1 and minutes are numbered from 0 to m−1.

That's how the digits are displayed on the clock. Please note that digit 1 is placed in the middle of its position.
A standard mirror is in use on the planet Lapituletti. Inhabitants often look at the reflection of the digital clocks in the mirror and feel happy when what you see on the reflected clocks is a valid time (that means that you see valid digits in the reflection and this time can be seen on the normal clocks at some moment of a day).
The image of the clocks in the mirror is reflected against a vertical axis.

The reflection is not a valid time.

The reflection is a valid time with h=24, m=60. However, for example, if h=10, m=60, then the reflection is not a valid time.
An inhabitant of the planet Lapituletti begins to look at a mirrored image of the clocks at some time moment s and wants to know the nearest future time moment (which can possibly happen on the next day), when the reflected clock time is valid.
It can be shown that with any h, m, s such a moment exists. If the reflected time is correct at the moment the inhabitant began to look at the clock, that moment is considered the nearest.
You are asked to solve the problem for several test cases.
拉皮图莱蒂星球的时间流逝方式与地球相同,但一天持续 h 小时,每小时持续 m 分钟。该星球的居民使用类似于地球的数字时钟。时钟以 HH:MM 格式显示时间(先以十进制显示小时数,然后(冒号后)再以十进制显示分钟数;若需构成两位数,则小时和分钟均用前导零补齐)。小时编号为 0 至 h−1,分钟编号为 0 至 m−1。

上图为时钟上各数字的显示样式。请注意:数字 1 位于其所在位置的正中央。
拉皮图莱蒂星球使用标准竖直镜面。居民常观察数字时钟在镜中的反射,并当镜中所见为一个有效时间时感到开心(即镜中反射出的数字均为有效数字,且该时间在正常时钟上某时刻确实存在)。
镜中时钟图像关于竖直轴对称反射。

该反射结果不是一个有效时间。

该反射结果是一个有效时间(此时 h=24,m=60)。然而,例如当 h=10、m=60 时,该反射结果就不是有效时间。
拉皮图莱蒂星球的一名居民从某一时刻 s 开始观察时钟的镜像,并希望知道下一个(可能在次日)使得镜中反射时间有效的最近未来时刻。
可以证明:对任意 h、m、s,这样的时刻必然存在。若居民开始观察时,镜中反射时间已是有效时间,则该起始时刻即为所求最近时刻。
你需要对多个测试用例求解该问题。
输入格式
The first line contains a single integer T (1≤T≤100) — the number of test cases.
The next 2⋅T lines contain the description of test cases. The description of each test case consists of two lines.
The first line of a test case contains two integers h, m (1≤h,m≤100).
The second line contains the start time s in the described format HH:MM.
第一行包含一个整数 T(1≤T≤100)—— 表示测试用例的数量。
接下来的 2⋅T 行描述了各个测试用例。每个测试用例的描述由两行组成。
每个测试用例的第一行包含两个整数 h、m(1≤h,m≤100)。
每个测试用例的第二行包含起始时间 s,格式为 HH:MM。
输出格式
For each test case output in a separate line the nearest moment in format HH:MM when the reflected time is correct.
对于每个测试用例,在单独一行中输出格式为 HH:MM 的最近时刻,使得该时刻在镜中的反射时间是正确的。
输入输出样例
输入#1
5 24 60 12:21 24 60 23:59 90 80 52:26 1 100 00:01 10 10 04:04
输出#1
12:21 00:00 52:28 00:00 00:00
说明/提示
In the second test case it is not hard to show that the reflection of 23:59 is incorrect, while the reflection of the moment 00:00 on the next day is correct.

在第二个测试用例中,不难证明 23:59 的镜像显示是错误的,而第二天 00:00 这一时刻的镜像显示是正确的。

输入解题思路,AI测评打分。不知道怎么写?