CF2228C1.Cirno and Number (Easy Version)

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Led On by a Cow to Visit Zenkou Temple

— Neo-traditionalism of Japan

This is the easy version of the problem. The difference between the versions is that in this version, n=2n=2. You can hack only if you solved all versions of this problem.

You are given a non-negative integer aa and a non-empty, strictly increasing sequence of digits dd of length nn, where 0≤di≤90 \le d_i \le 9.

Find the minimum value of ∣a−b∣|a - b| over all non-negative integers bb whose decimal representation contains only digits from dd.

由奶牛引路前往善光寺

——日本新传统主义

本题为简单版本。两个版本的区别在于:本版本中 n=2n=2。仅当您已解决本题所有版本时,才可进行 Hack。

给定一个非负整数 aa 和一个长度为 nn 的、非空且严格递增的数字序列 dd(即每位数字满足 0≤di≤90 \le d_i \le 9)。

请找出所有满足以下条件的非负整数 bb 中,∣a−b∣|a - b| 的最小值:bb 的十进制表示中仅包含来自序列 dd 的数字。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers aa and nn (0≤a≤10170\le a\le 10^{17}, n=2n=2).

The second line contains nn integers d1,d2,…,dnd_1,d_2,\ldots,d_n. It is guaranteed that 0≤d1<d2<…<dn≤90\le d_1 \lt d_2 \lt \ldots \lt d_n\le 9.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是测试用例的描述。

每个测试用例的第一行包含两个整数 aa 和 nn(0≤a≤10170\le a\le 10^{17},n=2n=2)。

第二行包含 nn 个整数 d1,d2,…,dnd_1,d_2,\ldots,d_n。保证 0≤d1<d2<…<dn≤90\le d_1 \lt d_2 \lt \ldots \lt d_n\le 9。

输出格式

For each test case, output the minimum value of ∣a−b∣|a - b|.

对于每个测试用例,输出 ∣a−b∣|a - b| 的最小值。

输入输出样例

  • 输入#1

    4
    0 2
    0 1
    11 2
    1 2
    222 2
    3 4
    3333 2
    6 7

    输出#1

    0
    0
    111
    2556

说明/提示

In the first test case, a=0a=0, b=0b=0, and ∣a−b∣=0|a - b|=0.

In the second test case, a=11a=11, b=11b=11, and ∣a−b∣=0|a - b|=0.

In the third test case, a=222a=222, b=333b=333, and ∣a−b∣=111|a - b|=111.

In the fourth test case, a=3333a=3333, b=777b=777, and ∣a−b∣=2556|a - b|=2556.

在第一个测试用例中,a=0a=0,b=0b=0,且 ∣a−b∣=0|a - b|=0。

在第二个测试用例中,a=11a=11,b=11b=11,且 ∣a−b∣=0|a - b|=0。

在第三个测试用例中,a=222a=222,b=333b=333,且 ∣a−b∣=111|a - b|=111。

在第四个测试用例中,a=3333a=3333,b=777b=777,且 ∣a−b∣=2556|a - b|=2556。

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

首页