「Cfz Round 2」How to Prove 题解

· · 题解

一道简单的构造题。

我们考虑先构造一个 0,接下来 n-1 个数,我们就可以构造 1,-1,2,-2 \ldots。

容易发现,这会产生大量的 0,1,-1,2 \ldots,抵消后就可以让 |\Omega(S)| 最小。

代码如下:

// 先搞点分,后面再调
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#define int long long
using namespace std;
signed main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        cout << "0 ";
        int pos = 1;
        int sgn = 1;
        for (int i = 2; i <= n; i++) {
            cout << pos * sgn << " ";
            sgn = -sgn;
            if (sgn == 1) pos++;
        }
        cout << endl;
    }
}