CF1681C.Double Sort
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays a and b, both consisting of n integers.
In one move, you can choose two indices i and j (1≤i,j≤n; i=j) and swap ai with aj and bi with bj. You have to perform the swap in both arrays.
You are allowed to perform at most 104 moves (possibly, zero). Can you make both arrays sorted in a non-decreasing order at the end? If you can, print any sequence of moves that makes both arrays sorted.
给你两个数组 a 和 b,它们均包含 n 个整数。
在一次操作中,你可以选择两个下标 i 和 j(满足 1≤i,j≤n 且 i=j),并同时交换 ai 与 aj,以及 bi 与 bj。即:必须在两个数组中同步执行该交换。
你最多可以执行 104 次操作(也可以不执行任何操作)。你能否通过若干次操作,使得两个数组最终都按非递减顺序排列?如果可以,请输出任意一组实现该目标的操作序列。
输入格式
The first line contains a single integer t (1≤t≤100) — the number of testcases.
The first line of each testcase contains a single integer n (2≤n≤100) — the number of elements in both arrays.
The second line contains n integers a1,a2,…,an (1≤ai≤n) — the first array.
The third line contains n integers b1,b2,…,bn (1≤bi≤n) — the second array.
第一行包含一个整数 t(1≤t≤100)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(2≤n≤100)—— 两个数组中元素的个数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)—— 第一个数组。
每个测试用例的第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤n)—— 第二个数组。
输出格式
For each testcase, print the answer. If it's impossible to make both arrays sorted in a non-decreasing order in at most 104 moves, print -1. Otherwise, first, print the number of moves k (0≤k≤104). Then print i and j for each move (1≤i,j≤n; i=j).
If there are multiple answers, then print any of them. You don't have to minimize the number of moves.
对于每个测试用例,输出答案。如果无法在至多 104 次操作内使两个数组均变为非递减顺序,则输出 -1。否则,首先输出操作次数 k(其中 0≤k≤104);然后对每次操作,输出对应的 i 和 j(其中 1≤i,j≤n,且 i=j)。
若存在多个合法答案,输出任意一个即可。你无需最小化操作次数。
输入输出样例
输入#1
3 2 1 2 1 2 2 2 1 1 2 4 2 3 1 2 2 3 2 3
输出#1
0 -1 3 3 1 3 2 4 3
输入解题思路,AI测评打分。不知道怎么写?