QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100

#12965. Omar 的 Bug

Estadísticas

Omar 是世界上最年轻的程序员,他才 11 个月大。他读过关于二分查找算法的内容,并决定自己写一个。

他编写了以下函数(其语法在 C++ 和 Java 中均有效,且功能相同):

int findFirstGreaterThanOrEqual(int array[], int N, int X) {
    int start = 0, end = N;
    while (start < end) {
        int middle = (start + end) / 2;
        if (array[middle] > X) {
            end = middle;
        } else {
            start = middle + 1;
        }
    }
    return start;
}

该函数在调用时始终满足以下条件:

  1. 第一个参数是一个包含至少 1 个且最多 99 个整数的数组。
  2. 数组包含不同的整数,且按升序排列。
  3. 数组中的整数均为正数,且每个数最大不超过 100。
  4. $N$ 是该数组中元素的个数。
  5. $X$ 是一个最大不超过 100 的正整数。

Omar 希望该函数按以下方式工作:

如果给定数组中没有大于或等于 $X$ 的整数,Omar 希望函数返回 $N$。否则,Omar 希望函数返回数组中第一个大于或等于 $X$ 的整数的下标(数组的第一个元素下标为 0)。

不幸的是,该函数存在一个 bug,导致在某些情况下返回错误的结果,而 Omar 无法找到这个 bug(他太小了)。你能帮他生成一些数组来测试他的函数吗?

输入格式

你的程序将在一组或多组测试数据上进行测试。输入的第一行是一个整数 $T$,表示测试数据的组数($1 \le T \le 100$)。接下来的每一行描述一组测试数据,包含 3 个由空格分隔的整数 $N, X, Y$($1 \le N \le 99$,$1 \le X \le 100$,$1 \le Y \le 2$)。$N$ 是第二个参数的值,$X$ 是第三个参数的值。如果 $Y=1$,你需要生成一个数组,当该数组以给定的参数传递给函数时,函数将返回正确的结果。如果 $Y=2$,你需要生成一个数组,当该数组以给定的参数传递给函数时,函数将返回错误的结果。在这两种情况下,生成的数组都必须满足上述条件。

注意,正确或错误的结果是相对于 Omar 希望函数实现的功能而言的。

输出格式

对于每组测试数据,在一行中打印 $N$ 个由空格分隔的整数,第一个整数是生成数组的第一个元素,第二个整数是第二个元素,依此类推(生成的数组应满足上述条件)。如果存在多个正确的解,请打印字典序最小的一个。

当比较两个长度相同的数组时,字典序较小的数组是指在第一个不同的位置上数值较小的那个数组。

样例

输入 1

2
3 3 1
4 7 2

输出 1

1 2 4
1 2 3 7

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.