aboutsummaryrefslogtreecommitdiff
path: root/01_introductory_problems/raab_game_i_3399.cpp
blob: bfa51938014d56b5689e2f13f19d80e478b01c04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <utility>
#include <vector>

class Game {
public:
	bool y;
	std::vector<int> a;
	std::vector<int> b;
	int apts = 0;
	int bpts = 0;

	Game(int n, bool w)
	    : y{w}, a{std::vector<int>(n)}, b{std::vector<int>(n)} {}

	void play(int i, int j) {
		this->a[this->next] = i;
		this->b[this->next] = j;
		this->apts += i > j;
		this->bpts += j > i;
		this->next++;
	}

	friend std::ostream& operator<<(std::ostream& os, const Game g) {
		if (!g.y) {
			os << "NO\n";
		} else {
			os << "YES\n";
			for (auto x : g.a)
				os << x << " ";
			os << "\n";
			for (auto x : g.b)
				os << x << " ";
			os << "\n";
		}
		return os;
	}
private:
	int next = 0;
};

Game play(int n, int a, int b) {
	if (a + b > n)
		return Game(1, false);

	Game g(n, true);
	for (int i = 0; i < n - (a+b); i++)
		g.play(i+1, i+1);
	for (int i = 0; i < a; i++)
		g.play(n-a+i+1, n-(a+b)+i+1);
	for (int i = 0; i < b; i++)
		g.play(n-(a+b)+i+1, n-b+i+1);

	if (g.apts != a || g.bpts != b)
		g.y = false;

	return g;
}

int main() {
	int n, a, b, t;
	std::cin >> t;
	for (int i = 0; i < t; i++) {
		std::cin >> n >> a >> b;
		std::cout << play(n, a, b);
	}
}

Generated with cgit - Back to sebastiano.tronto.net