Tc14

Staircase Game

Oct 14th, 2020
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ve vector
  4.  
  5. ve<int> Max = { 40, 40, 10 };
  6. int A = 0;
  7. int B = 1;
  8. int C = 2;
  9.  
  10. map<ve<int>, bool> Win;
  11.  
  12. bool f(ve<int>& State) {
  13.  
  14.     bool win;
  15.     ve<int> StateNew;
  16.  
  17.     if (Win.find(State) == Win.end()) {
  18.         win = false;
  19.  
  20.         for (int i = 0; i < State.size(); i++) {
  21.             for (int k = 1; k <= State[i]; k++) {
  22.  
  23.                 StateNew = State;
  24.                 StateNew[i] -= k;
  25.                 if (!f(StateNew)) win = true;
  26.  
  27.                 for (int j = 0; j < i; j++) {
  28.                     StateNew = State;
  29.                     StateNew[i] -= k;
  30.                     StateNew[j] += k;
  31.                     if (!f(StateNew)) win = true;
  32.                 }
  33.             }
  34.         }
  35.  
  36.         Win[State] = win;
  37.     }
  38.  
  39.     return Win[State];
  40. }
  41.  
  42. int main() {
  43.  
  44.     ve<int> State;
  45.  
  46.     State = Max;
  47.     for (int k = 0; k <= Max[C]; k++) {
  48.         State[C] = k;
  49.  
  50.         cout << k << endl;
  51.         cout << endl;
  52.  
  53.         for (int i = 0; i <= Max[A]; i++) {
  54.             State[A] = i;
  55.  
  56.             for (int j = 0; j <= Max[B]; j++) {
  57.                 State[B] = j;
  58.  
  59.                 if (f(State)) cout << ". ";
  60.                 else cout << "X ";
  61.             }
  62.             cout << endl;
  63.         }
  64.         cout << endl;
  65.     }
  66.  
  67.     return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment