CF384B.Multitasking
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.
Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position i is strictly greater than the value at position j.
Iahub wants to find an array of pairs of distinct indices that, chosen in order, sort all of the n arrays in ascending or descending order (the particular order is given in input). The size of the array can be at most
(at most
pairs). Help Iahub, find any suitable array.
Iahub 希望提升自己的多任务处理能力。为此,他希望同时对 $ n $ 个数组进行排序,每个数组包含 $ m $ 个整数。
Iahub 可以选择一对互异的下标 $ i $ 和 $ j $(满足 $ 1 \leq i, j \leq m $ 且 $ i \neq j $)。随后,在每一个数组中,仅当位置 $ i $ 处的值严格大于位置 $ j $ 处的值时,才交换这两个位置上的值。
Iahub 希望找到一个由互异下标对构成的序列,按该序列依次执行上述操作后,能使全部 $ n $ 个数组均按升序或降序排列(具体要求的排序顺序由输入给出)。该序列的长度至多为
(即最多
对)。请帮助 Iahub 找出任意一个满足条件的序列。
输入格式
The first line contains three integers n (1 ≤ n ≤ 1000), m (1 ≤ m ≤ 100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each element x of the array i, 1 ≤ x ≤ 106 holds.
第一行包含三个整数 n(1≤n≤1000)、m(1≤m≤100)和 k。若 k=0,则数组需按升序排列;若 k=1,则数组需按降序排列。接下来的 n 行中,第 i 行包含 m 个以空格分隔的整数,表示第 i 个数组。对于数组 i 中的每个元素 x,均满足 1≤x≤106。
输出格式
On the first line of the output print an integer p, the size of the array (p can be at most
). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices.
If there are multiple correct answers, you can print any.
在输出的第一行打印一个整数 p,表示数组的大小(p 最多为
)。接下来的 p 行中,每行必须包含两个互不相同的整数 i 和 j(满足 1 ≤ i, j ≤ m 且 i = j),表示所选的下标。
如果存在多个正确答案,输出任意一个即可。
输入输出样例
输入#1
2 5 0 1 3 2 5 4 1 4 3 2 5
输出#1
3 2 4 2 3 4 5
输入#2
3 2 1 1 2 2 3 3 4
输出#2
1 2 1
说明/提示
Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5].
考虑第一个样例。第一次操作后,两个数组变为 [1, 3, 2, 5, 4] 和 [1, 2, 3, 4, 5]。第二次操作后,两个数组变为 [1, 2, 3, 5, 4] 和 [1, 2, 3, 4, 5]。第三次操作后,两个数组变为 [1, 2, 3, 4, 5] 和 [1, 2, 3, 4, 5]。
输入解题思路,AI测评打分。不知道怎么写?