309861: CF1747B. BAN BAN

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

BAN BAN

题意翻译

给定一个整数 $ n $。 定义 $ s(n) $ 是这个字符串 "BAN"串联 $ n $ 次。 例如, $ s(1) $ = "BAN", $ s(3) $ = "BANBANBAN". 注意此时字符串 长度 $s(n) $ 等于 $ 3n $。 考虑 $ s(n) $ , 你可以执行以下操作 $ s(n) $ 任意次数 (可能为零): - 选择两个任意的指针 $ i $ and $ j $ $ (1 \leq i, j \leq 3n, i \ne j) $ 。 - 然后交换 $ s(n)_i $ 和 $ s(n)_j $ 。 你希望字符串 "BAN" 不作为字串出现在 $ s(n) $ 内. 要实现这一点,你需要执行的最小操作数是多少?另外,找到这样一个最短的操作顺序。 如果 $a$ 可以通过删除几个(可能为零或全部)字符从 $b$ 获得,则字符串 $a$ 是字符串 $b$ 的子序列。

题目描述

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 \leq i, j \leq 3n, i \ne 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 \leq t \leq 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 \leq n \leq 100) $ .

输出格式


For each test case, in the first line output $ m $ ( $ 0 \le m \le 10^5 $ ) — the minimum number of operations required. It's guaranteed that the objective is always achievable in at most $ 10^5 $ operations under the constraints of the problem. Then, output $ m $ lines. The $ k $ -th of these lines should contain two integers $ i_k $ , $ j_k $ $ (1\leq i_k, j_k \leq 3n, i_k \ne j_k) $ denoting that you want to swap characters at indices $ i_k $ and $ j_k $ 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.

Input

题意翻译

给定一个整数 $ n $。 定义 $ s(n) $ 是这个字符串 "BAN"串联 $ n $ 次。 例如, $ s(1) $ = "BAN", $ s(3) $ = "BANBANBAN". 注意此时字符串 长度 $s(n) $ 等于 $ 3n $。 考虑 $ s(n) $ , 你可以执行以下操作 $ s(n) $ 任意次数 (可能为零): - 选择两个任意的指针 $ i $ and $ j $ $ (1 \leq i, j \leq 3n, i \ne j) $ 。 - 然后交换 $ s(n)_i $ 和 $ s(n)_j $ 。 你希望字符串 "BAN" 不作为字串出现在 $ s(n) $ 内. 要实现这一点,你需要执行的最小操作数是多少?另外,找到这样一个最短的操作顺序。 如果 $a$ 可以通过删除几个(可能为零或全部)字符从 $b$ 获得,则字符串 $a$ 是字符串 $b$ 的子序列。

Output

题目大意:
给定一个整数n。定义s(n)为字符串"BAN"重复n次。例如,s(1)="BAN", s(3)="BANBANBAN"。注意字符串s(n)的长度为3n。

你可以对s(n)执行以下操作任意次数(可能为零):

- 选择两个不同的索引i和j (1≤i,j≤3n, i≠j)。
- 然后交换s(n)_i和s(n)_j的字符。

你的目标是通过上述操作使得字符串"BAN"不出现在s(n)中作为子序列。求实现这一目标所需的最小操作数,并找到这样一个最短的操作顺序。

输入输出数据格式:
输入包括多个测试用例。第一行包含一个整数t (1≤t≤100) — 测试用例的数量。接下来是每个测试用例的描述。

每个测试用例只有一行,包含一个整数n (1≤n≤100)。

输出对于每个测试用例,第一行输出m (0≤m≤10^5) — 实现目标所需的最小操作数。题目保证在问题的约束下,目标总是可以通过最多10^5次操作实现。

然后输出m行。第k行应包含两个整数i_k, j_k (1≤i_k, j_k≤3n, i_k≠j_k),表示在第k次操作中你想要交换索引i_k和j_k的字符。

在所有m次操作之后,"BAN"不得出现在s(n)中作为子序列。

如果有多个可能的答案,输出其中任意一个。题目大意: 给定一个整数n。定义s(n)为字符串"BAN"重复n次。例如,s(1)="BAN", s(3)="BANBANBAN"。注意字符串s(n)的长度为3n。 你可以对s(n)执行以下操作任意次数(可能为零): - 选择两个不同的索引i和j (1≤i,j≤3n, i≠j)。 - 然后交换s(n)_i和s(n)_j的字符。 你的目标是通过上述操作使得字符串"BAN"不出现在s(n)中作为子序列。求实现这一目标所需的最小操作数,并找到这样一个最短的操作顺序。 输入输出数据格式: 输入包括多个测试用例。第一行包含一个整数t (1≤t≤100) — 测试用例的数量。接下来是每个测试用例的描述。 每个测试用例只有一行,包含一个整数n (1≤n≤100)。 输出对于每个测试用例,第一行输出m (0≤m≤10^5) — 实现目标所需的最小操作数。题目保证在问题的约束下,目标总是可以通过最多10^5次操作实现。 然后输出m行。第k行应包含两个整数i_k, j_k (1≤i_k, j_k≤3n, i_k≠j_k),表示在第k次操作中你想要交换索引i_k和j_k的字符。 在所有m次操作之后,"BAN"不得出现在s(n)中作为子序列。 如果有多个可能的答案,输出其中任意一个。

加入题单

上一题 下一题 算法标签: