构造题集合

CF 1630 A 构造 二进制

k 在 0 ~ n - 1 之间
而我们可以很轻松的构造出 为0的时候
把数分成两半,前一半和后一半反向与的值,都刚好为0
0,是万精油,可以消去任意一个数,所以就有 n - 1 种数可以表示出来了 即 [0, n - 2]
最后再构造一下 n - 1 即可
https://codeforces.com/problemset/problem/1630/A

#include "bits/stdc++.h"

using namespace std;
int t, n, m;
int main () {
    cin >> t;
    while (t --) {
        cin >> n >> m;
        if (m == 0) {
            for (int i = 0; i < n / 2; ++ i)
                cout << i << " " << n - 1 - i << endl;
        } else if (m == n - 1) {
            if (n == 4) cout << -1 << endl;
            else {
                cout << n - 1 << " " << n - 2 << endl;
                cout << 1 << " " << n - 3 << endl;
                cout << 0 << " " << 2 << endl;
                for (int i = 3, k = 0; k < n / 2 - 3; ++ k, ++ i)
                    cout << i << " " << n - 1 - i << endl;
            }
        } else {
            cout << 0 << " " << n - 1 - m << endl;
            cout << m << " " << n - 1 << endl;
            for (int i = 1; i < n / 2; ++ i) {
                int a = n - 1 - i;
                if (i == m || a == m) continue;
                cout << i << " " << a << endl;
            }
        };
    }
    return 0;
}
上一篇:python 脚本传递参数


下一篇:Symfony 从路由认识它