跳到正文

题解

CF1968E 题解

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

文章信息

发布
2024年5月4日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 1 分钟
题目
CF1968E

版本

  1. v1当前

思路

赛时始终百思不得其解,赛后看了他人代码恍然大悟。

先看一下我画的 n=5n=5 时的做法(x 表示选择的点):

代码
xx...
.....
..x..
...x.
....x

首先距离为 00 是一定存在的,然后距离为 11 就在第一行,22 在 ai,i,ai+1,i+1(3≤i<n)a_{i,i},a_{i+1,i+1}(3\le i<n),33 在 a1,2,a3,3a_{1,2},a_{3,3},44 在 a1,1,a3,3a_{1,1},a_{3,3},2i−32i-3 在 a1,2,ai,ia_{1,2},a_{i,i},2i−22i-2 在 a1,1,ai,ia_{1,1},a_{i,i},这一来,0∼2n−20\sim 2n-2 都凑齐了(n=2,3n=2,3 除外,但也是最优解)。

代码

C++
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int t, n;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> t;
	while (t --) {
		cin >> n;
		cout << "1 1\n1 2\n";
		for (int i = 3; i <= n; ++ i)
			cout << i << ' ' << i << '\n';
		cout << '\n';
	}
	return 0;
}
原文