CF1857B.Maximum Rounding

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given a natural number xx. You can perform the following operation:

  • choose a positive integer kk and round xx to the kk-th digit

Note that the positions are numbered from right to left, starting from zero. If the number has kk digits, it is considered that the digit at the kk-th position is equal to 00.

The rounding is done as follows:

  • if the digit at the (k−1)(k-1)-th position is greater than or equal to 55, then the digit at the kk-th position is increased by 11, otherwise the digit at the kk-th position remains unchanged (mathematical rounding is used).

  • if before the operations the digit at the kk-th position was 99, and it should be increased by 11, then we search for the least position k′k' (k′>kk' \gt k), where the digit at the k′k'-th position is less than 99 and add 11 to the digit at the k′k'-th position. Then we assign k=k′k=k'.

  • after that, all digits which positions are less than kk are replaced with zeros.

Your task is to make xx as large as possible, if you can perform the operation as many times as you want.

For example, if xx is equal to 34513451, then if you choose consecutively:

  • k=1k=1, then after the operation xx will become 34503450
  • k=2k=2, then after the operation xx will become 35003500
  • k=3k=3, then after the operation xx will become 40004000
  • k=4k=4, then after the operation xx will become 00

To maximize the answer, you need to choose k=2k=2 first, and then k=3k=3, then the number will become 40004000.

给定一个自然数 xx。你可以执行以下操作:

  • 选择一个正整数 kk,并将 xx 四舍五入到第 kk 位。

注意:位数编号从右向左,起始位置为 00。若该数仅有 kk 位数字,则认为其第 kk 位上的数字为 00。

四舍五入规则如下:

  • 若第 (k−1)(k-1) 位上的数字大于或等于 55,则将第 kk 位上的数字加 11;否则第 kk 位上的数字保持不变(采用数学四舍五入)。

  • 若在操作前第 kk 位上的数字为 99,且此时需将其加 11,则需寻找最小的位置 k′k'(满足 k′>kk' \gt k),使得第 k′k' 位上的数字小于 99,然后将第 k′k' 位上的数字加 11,并令 k=k′k = k'。

  • 此后,所有位置编号小于 kk 的数字均被替换为 00。

你的任务是:在可以任意多次执行该操作的前提下,使 xx 尽可能大。

例如,若 x=3451x = 3451,则依次选择:

  • k=1k=1,操作后 xx 变为 34503450
  • k=2k=2,操作后 xx 变为 35003500
  • k=3k=3,操作后 xx 变为 40004000
  • k=4k=4,操作后 xx 变为 00

为使结果最大化,应首先选择 k=2k=2,再选择 k=3k=3,此时该数变为 40004000。

输入格式

The first line contains a single integer tt (1≤t≤1041\le t\le 10^4) — the number of test cases.

Each test case consists of positive integer xx with a length of up to 2⋅1052 \cdot 10^5. It is guaranteed that there are no leading zeros in the integer.

It is guaranteed that the sum of the lengths of all integers xx over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041\le t\le 10^4),表示测试用例的数量。

每个测试用例包含一个正整数 xx,其长度最多为 2⋅1052 \cdot 10^5。保证该整数不包含前导零。

保证所有测试用例中整数 xx 的长度之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each set of input data, output the maximum possible value of xx after the operations. The number should not have leading zeros in its representation.

对于每组输入数据,输出执行操作后 xx 的最大可能值。该数字在其表示中不能有前导零。

输入输出样例

  • 输入#1

    10
    1
    5
    99
    913
    1980
    20444
    20445
    60947
    419860
    40862016542130810467

    输出#1

    1
    10
    100
    1000
    2000
    20444
    21000
    100000
    420000
    41000000000000000000

说明/提示

In the first sample, it is better not to perform any operations.

In the second sample, you can perform one operation and obtain 1010.

In the third sample, you can choose k=1k=1 or k=2k=2. In both cases the answer will be 100100.

在第一个样例中,不执行任何操作更优。

在第二个样例中,你可以执行一次操作,得到 1010。

在第三个样例中,你可以选择 k=1k=1 或 k=2k=2。两种情况下答案均为 100100。

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

首页