各位数字全不同的最近一天(MM/DD/YYYY)
Distinct Date II
题目详情
找“最近(最晚)的一天”的日期,使得按 表示时出现的所有数字都互不相同。
例如 是合法的。用 的形式给出答案。
Find the most recent date where all of the digits, when expressed in the form are distinct. For example, would be a valid date. Express your answer in the form .
解析
要尽量晚,年份应尽量大且仍在过去。
分析可知年份必须以 1 开头;为最大化年份,取 。
此时月份首位只能是 0,选最大的可用月份为 06;再选可行的最大日期为 25。
因此日期为 ,答案为
Original Explanation
Our goal now is to maximize the year to make it as close as possible to our present date. The biggest thing to first note is that the year must start with a . Suppose that it started with a . We know that the first is either a or . If it is a , then the day either starts with a or is . Note that the other can't be a in this case; otherwise, that would eliminate the day possibilities. If the month starts with a , then the day either contains or is . However, since the is already used in the part, regardless of what we start with, we can't get a year that is in the past.
Therefore, the year must start with a . To maximize the year, we can just fix the rest as the three largest integers. Namely, , so our year is . Since the year starts with , the month must start with . Then, we choose the largest month integer remaining, which is . Then, we must pick the largest possible day among the integers remaining. We can see that is the largest possible day, as anything starting with is not possible. Therefore, our date is .