返回题库

各位数字全不同的下一天(MM/DD/YYYY)

Distinct Date I

专题
Algorithmic Programming / 算法编程
难度
L4

题目详情

找“下一天”的日期,使得按 MM/DD/YYYYMM/DD/YYYY 表示时出现的所有数字都互不相同。

例如 01/23/456701/23/4567 是合法的。用 MMDDYYYYMMDDYYYY 的形式给出答案。

Find the next date where all of the digits, when expressed in the form MM/DD/YYYYMM/DD/YYYY are distinct. For example, 01/23/456701/23/4567 would be a valid date. Express your answer in the form MMDDYYYYMMDDYYYY.

解析

为了尽量早,优先最小化年份,并分析月日中必须包含的 0/1/2 的位置。

综合约束后可得到最早满足条件的日期为 06/17/234506/17/2345,因此答案是

06172345.06172345.

Original Explanation

We want to minimize the year, as that will be the biggest influence on how soon it is. Note that the first MM is either 00 or 11. If the first MM is 00, then the first day must be 11 or 22 OR the day is 3131 (3030 doesn't work since we already have a 00). If the first MM is 11, then either the second MM is a 00 OR the second MM is a 22 and the day contains a 00 somewhere. Therefore, these both imply that the 00 and either the 11 or 22 must be used in the MMDDMMDD portion. Since we ideally don't want to skip 10001000 years, we should put the 22 in the year portion, so thus far, we have that our date is in the form 0M/1D/2YYY0M/1D/2YYY. After this, it's just an objective to minimize the rest of the digits. Namely, YYY=345YYY = 345, as that is the smallest number that can be made with the remaining digits. Then, we want to minimize the month, so M=6M = 6. Then, lastly, D=7D = 7, as that is the smallest remaining number. Our answer is therefore 06/17/234506/17/2345.