CF1630A.And Matching
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a set of n ( n is always a power of 2 ) elements containing all integers 0,1,2,…,n−1 exactly once.
Find 2n pairs of elements such that:
- Each element in the set is in exactly one pair.
- The sum over all pairs of the bitwise AND of its elements must be exactly equal to k . Formally, if ai and bi are the elements of the i -th pair, then the following must hold: $$$$\sum_{i=1}^{n/2}{a_i & b_i} = k, $$ where \\& denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print −1$$ instead.
输入格式
The input consists of multiple test cases. The first line contains a single integer t ( 1≤t≤400 ) — the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers n and k ( 4≤n≤216 , n is a power of 2 , 0≤k≤n−1 ).
The sum of n over all test cases does not exceed 216 . All test cases in each individual input will be pairwise different.
输出格式
For each test case, if there is no solution, print a single line with the integer −1 .
Otherwise, print 2n lines, the i -th of them must contain ai and bi , the elements in the i -th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
输入输出样例
输入#1
4 4 0 4 1 4 2 4 3
输出#1
0 3 1 2 0 2 1 3 0 1 2 3 -1
说明/提示
In the first test, (0&3)+(1&2)=0 .
In the second test, (0&2)+(1&3)=1 .
In the third test, (0&1)+(2&3)=2 .
In the fourth test, there is no solution.