CF1647A.Madoka and Math Dad
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Madoka finally found the administrator password for her computer. Her father is a well-known popularizer of mathematics, so the password is the answer to the following problem.
Find the maximum decimal number without zeroes and with no equal digits in a row, such that the sum of its digits is n.
Madoka is too tired of math to solve it herself, so help her to solve this problem!
魔理沙终于找到了她电脑的管理员密码。她的父亲是一位著名的数学普及者,因此密码是以下问题的答案。
找出一个十进制数,它满足:不含数字 0、相邻数字互不相同,且各位数字之和为 n。在所有满足条件的数中,求最大的那个。
魔理沙已经对数学感到厌倦,无法独自解决这个问题,所以请帮她解出此题!
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. Description of the test cases follows.
The only line of each test case contains an integer n (1≤n≤1000) — the required sum of the digits.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例仅有一行,包含一个整数 n(1≤n≤1000),表示所要求的各位数字之和。
输出格式
For each test case print the maximum number you can obtain.
对于每个测试用例,输出你能得到的最大数。
输入输出样例
输入#1
5 1 2 3 4 5
输出#1
1 2 21 121 212
说明/提示
The only numbers with the sum of digits equal to 2 without zeros are 2 and 11. But the last one has two ones in a row, so it's not valid. That's why the answer is 2.
The only numbers with the sum of digits equal to 3 without zeros are 111, 12, 21, and 3. The first one has 2 ones in a row, so it's not valid. So the maximum valid number is 21.
The only numbers with the sum of digits equals to 4 without zeros are 1111, 211, 121, 112, 13, 31, 22, and 4. Numbers 1111, 211, 112, 22 aren't valid, because they have some identical digits in a row. So the maximum valid number is 121.
各位数字之和等于 2 且不含数字 0 的数只有 2 和 11。但后者包含两个连续的 1,因此不满足条件。故答案为 2。
各位数字之和等于 3 且不含数字 0 的数只有 111、12、21 和 3。其中 111 包含两个连续的 1,因此不满足条件。故最大的合法数为 21。
各位数字之和等于 4 且不含数字 0 的数有 1111、211、121、112、13、31、22 和 4。其中 1111、211、112、22 均包含连续的相同数字,因此不满足条件。故最大的合法数为 121。
输入解题思路,AI测评打分。不知道怎么写?