CF1747B.BAN BAN
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer n .
Let's define s(n) as the string "BAN" concatenated n times. For example, s(1) = "BAN", s(3) = "BANBANBAN". Note that the length of the string s(n) is equal to 3n .
Consider s(n) . You can perform the following operation on s(n) any number of times (possibly zero):
- Select any two distinct indices i and j (1≤i,j≤3n,i=j) .
- Then, swap s(n)i and s(n)j .
You want the string "BAN" to not appear in s(n) as a subsequence. What's the smallest number of operations you have to do to achieve this? Also, find one such shortest sequence of operations.
A string a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters.
输入格式
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.
The only line of each test case contains a single integer n (1≤n≤100) .
输出格式
For each test case, in the first line output m ( 0≤m≤105 ) — the minimum number of operations required. It's guaranteed that the objective is always achievable in at most 105 operations under the constraints of the problem.
Then, output m lines. The k -th of these lines should contain two integers ik , jk (1≤ik,jk≤3n,ik=jk) denoting that you want to swap characters at indices ik and jk at the k -th operation.
After all m operations, "BAN" must not appear in s(n) as a subsequence.
If there are multiple possible answers, output any.
输入输出样例
输入#1
2 1 2
输出#1
1 1 2 1 2 6
说明/提示
In the first testcase, $s(1) = $ "BAN", we can swap s(1)1 and s(1)2 , converting s(1) to "ABN", which does not contain "BAN" as a subsequence.
In the second testcase, $s(2) = $ "BANBAN", we can swap s(2)2 and s(2)6 , converting s(2) to "BNNBAA", which does not contain "BAN" as a subsequence.