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 nn.

Madoka is too tired of math to solve it herself, so help her to solve this problem!

魔理沙终于找到了她电脑的管理员密码。她的父亲是一位著名的数学普及者,因此密码是以下问题的答案。

找出一个十进制数,它满足:不含数字 0、相邻数字互不相同,且各位数字之和为 nn。在所有满足条件的数中,求最大的那个。

魔理沙已经对数学感到厌倦,无法独自解决这个问题,所以请帮她解出此题!

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. Description of the test cases follows.

The only line of each test case contains an integer nn (1≤n≤10001 \le n \le 1000) — the required sum of the digits.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含一个整数 nn(1≤n≤10001 \le n \le 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 22 without zeros are 22 and 1111. But the last one has two ones in a row, so it's not valid. That's why the answer is 22.

The only numbers with the sum of digits equal to 33 without zeros are 111111, 1212, 2121, and 33. The first one has 22 ones in a row, so it's not valid. So the maximum valid number is 2121.

The only numbers with the sum of digits equals to 44 without zeros are 11111111, 211211, 121121, 112112, 1313, 3131, 2222, and 44. Numbers 11111111, 211211, 112112, 2222 aren't valid, because they have some identical digits in a row. So the maximum valid number is 121121.

各位数字之和等于 22 且不含数字 00 的数只有 22 和 1111。但后者包含两个连续的 11,因此不满足条件。故答案为 22。

各位数字之和等于 33 且不含数字 00 的数只有 111111、1212、2121 和 33。其中 111111 包含两个连续的 11,因此不满足条件。故最大的合法数为 2121。

各位数字之和等于 44 且不含数字 00 的数有 11111111、211211、121121、112112、1313、3131、2222 和 44。其中 11111111、211211、112112、2222 均包含连续的相同数字,因此不满足条件。故最大的合法数为 121121。

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

首页