diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
| commit | 96254947699986c59f0dc63d69fd4b76bd3ed43e (patch) | |
| tree | 6c4dca945d7f7427c48be234d827fe4d33be02c5 /01_introductory_problems/raab_game_i_3399.cpp | |
| download | cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.tar.gz cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.zip | |
Initial commit
Diffstat (limited to '01_introductory_problems/raab_game_i_3399.cpp')
| -rw-r--r-- | 01_introductory_problems/raab_game_i_3399.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/01_introductory_problems/raab_game_i_3399.cpp b/01_introductory_problems/raab_game_i_3399.cpp new file mode 100644 index 0000000..bfa5193 --- /dev/null +++ b/01_introductory_problems/raab_game_i_3399.cpp | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | #include <iostream> | ||
| 2 | #include <utility> | ||
| 3 | #include <vector> | ||
| 4 | |||
| 5 | class Game { | ||
| 6 | public: | ||
| 7 | bool y; | ||
| 8 | std::vector<int> a; | ||
| 9 | std::vector<int> b; | ||
| 10 | int apts = 0; | ||
| 11 | int bpts = 0; | ||
| 12 | |||
| 13 | Game(int n, bool w) | ||
| 14 | : y{w}, a{std::vector<int>(n)}, b{std::vector<int>(n)} {} | ||
| 15 | |||
| 16 | void play(int i, int j) { | ||
| 17 | this->a[this->next] = i; | ||
| 18 | this->b[this->next] = j; | ||
| 19 | this->apts += i > j; | ||
| 20 | this->bpts += j > i; | ||
| 21 | this->next++; | ||
| 22 | } | ||
| 23 | |||
| 24 | friend std::ostream& operator<<(std::ostream& os, const Game g) { | ||
| 25 | if (!g.y) { | ||
| 26 | os << "NO\n"; | ||
| 27 | } else { | ||
| 28 | os << "YES\n"; | ||
| 29 | for (auto x : g.a) | ||
| 30 | os << x << " "; | ||
| 31 | os << "\n"; | ||
| 32 | for (auto x : g.b) | ||
| 33 | os << x << " "; | ||
| 34 | os << "\n"; | ||
| 35 | } | ||
| 36 | return os; | ||
| 37 | } | ||
| 38 | private: | ||
| 39 | int next = 0; | ||
| 40 | }; | ||
| 41 | |||
| 42 | Game play(int n, int a, int b) { | ||
| 43 | if (a + b > n) | ||
| 44 | return Game(1, false); | ||
| 45 | |||
| 46 | Game g(n, true); | ||
| 47 | for (int i = 0; i < n - (a+b); i++) | ||
| 48 | g.play(i+1, i+1); | ||
| 49 | for (int i = 0; i < a; i++) | ||
| 50 | g.play(n-a+i+1, n-(a+b)+i+1); | ||
| 51 | for (int i = 0; i < b; i++) | ||
| 52 | g.play(n-(a+b)+i+1, n-b+i+1); | ||
| 53 | |||
| 54 | if (g.apts != a || g.bpts != b) | ||
| 55 | g.y = false; | ||
| 56 | |||
| 57 | return g; | ||
| 58 | } | ||
| 59 | |||
| 60 | int main() { | ||
| 61 | int n, a, b, t; | ||
| 62 | std::cin >> t; | ||
| 63 | for (int i = 0; i < t; i++) { | ||
| 64 | std::cin >> n >> a >> b; | ||
| 65 | std::cout << play(n, a, b); | ||
| 66 | } | ||
| 67 | } | ||
