跳到正文

个人记录

?

yh2022mayu约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define x first
#define y second
#define vc vector
#define vci vc<int>
#define psb push_back
using namespace std;
int a, b, ls;
vc<pii > ans;
int main(){
	cin >> a >> b;
	if(!b){
		if(a == 3 || a == 1){
			cout << 0;
			return 0;
		}
		cout << a + 1 << endl;
		for(int i = 1; i <= a; i++) cout << 1 << ' ' << i + 1 << endl;
		return 0;
	}
	if(b + 2 > a){
		cout << 0;
		return 0;
	}
	ans.psb({1, 2});
	ans.psb({1, 3});
	ans.psb({1, 4});
	ls = 4;
	for(int i = 4, j = 1; j < b; i += 2, j++){
		ans.psb({i, i + 1});
		ans.psb({i, i + 2});
		ls = i + 2;
	}
	a -= b + 2;
	if(a == 1){
		cout << 0;
		return 0;
	}
	cout << ls + a + 1 << endl;
	for(pii res : ans) cout << res.x << ' ' << res.y << endl;
	for(int i = 0; i <= a; i++) cout << ls << ' ' << ls + i + 1 << endl;
	return 0;
}
原文