cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

raab_game_i_3399.cpp (1157B)


      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 }