跳到正文

题解

「Cfz Round 2」How to Prove 题解

lkrqwq约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月18日
篇幅
约 1 分钟
题目
P10306

版本

  1. v1当前

一道简单的构造题。

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

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

代码如下:

C++
// 先搞点分,后面再调
#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;
	}
}
原文