跳到正文

题解

CF1990B 题解

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

文章信息

发布
2024年7月21日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 1 分钟
获赞
3
题目
CF1990B

版本

  1. v1当前

思路

y<xy<x?第一反应:a1∼ay−1=−1,ay∼ax=1,ax+1∼an=−1a_1\sim a_{y-1}=-1,a_y\sim a_x=1,a_{x+1}\sim a_n=-1。然后你会开心地发现你 WA Pretest #2 了。这里给出一组 Hack:6 2 1。

终于明白为什么是 y<xy<x 而不是 y≤xy\le x 了。我们只要 ay∼ax=1a_y\sim a_x=1,前后两端都是 −1,1-1,1 交替就行辣。

代码

C++
# include <bits/stdc++.h>
# define I return
# define AK 0
# define IOI ;
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int t, n, x, y;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> t;
	while (t --) {
		cin >> n >> x >> y;
		for (int i = y - 1; i; -- i)
			cout << (i & 1 ? "-1 " : "1 ");
		for (int i = y; i <= x; ++ i)
			cout << "1 ";
		for (int i = 1, tmp = n - x; i <= tmp; ++ i)
			cout << (i & 1 ? "-1 " : "1 ");
		cout << '\n';
	}
	I AK IOI
}
原文
存档评论2 条抓取于