Advertisement
Guest User

Untitled

a guest
May 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. struct Game {
  7.   int state[5][5];
  8.   bool diagMajor;
  9.   bool diagMinor;
  10.   bool row[5];
  11.   bool col[5];
  12.   int aRow[5];
  13.   int aCol[5];
  14.  
  15.   Game() {
  16.     diagMajor = diagMinor = false;
  17.    
  18.     for(int j = 0; j < 5; j++) row[j] = false;
  19.     for(int j = 0; j < 5; j++) col[j] = false;
  20.    
  21.     for(int j = 0; j < 5; j++) aRow[j] = false;
  22.     for(int j = 0; j < 5; j++) aCol[j] = false;
  23.    
  24.     for(int r = 0; r < 5; r++) {
  25.       for(int c = 0; c < 5; c++) {
  26.         state[r][c] = 0;
  27.       }
  28.     }
  29.   }
  30.  
  31.   bool aliceMove(int t) {
  32.     int r = (t - 1) / 5;
  33.     int c = (t - 1) % 5;
  34.    
  35.     if(state[r][c] != 0) {
  36.       return false;
  37.     }
  38.    
  39.     state[r][c] = 1;
  40.     aRow[r]++;
  41.     aCol[c]++;
  42.     return true;
  43.   }
  44.  
  45.   int moveId(int r, int c) {
  46.     return 5 * r + c + 1;
  47.   }
  48.  
  49.   int makeMove(int r, int c) {
  50.     if(r == -1) return -1;
  51.    
  52.     state[r][c] = 2;
  53.     row[r] = true;
  54.     col[c] = true;
  55.     if(r == c) diagMajor = true;
  56.     if(r + c == 4) diagMinor = true;
  57.     return moveId(r, c);
  58.   }
  59.  
  60.   int bestBobMove() {
  61.     int r = -1, c = -1, score = -1;
  62.    
  63.     for(int tr = 0; tr < 5; tr++) {
  64.       for(int tc = 0; tc < 5; tc++) {
  65.         if(state[tr][tc] != 0) continue;
  66.        
  67.         int ts = 0;
  68.         if(not diagMajor) ts += 15 * (tr == tc);
  69.         if(not diagMinor) ts += 15 * (tr + tc == 4);
  70.         ts += 5 * ((not row[tr]) + (not col[tc]));
  71.         ts += max(aRow[tr], aCol[tc]);
  72.        
  73.         if(ts > score) {
  74.           score = ts;
  75.           r = tr;
  76.           c = tc;
  77.         }
  78.       }
  79.     }
  80.    
  81.     return makeMove(r, c);
  82.   }
  83.  
  84. };
  85.  
  86.  
  87. void test() {
  88.   Game G;
  89.  
  90.   for(int i = 0; i < 25; i++) {
  91.     int t;
  92.     cin >> t;
  93.     if(not G.aliceMove(t)) continue;
  94.     int u = G.bestBobMove();
  95.     if(u != -1) {
  96.       cout << u << ' ';
  97.     }
  98.   }
  99.  
  100.   cout << '\n';
  101. }
  102.  
  103.  
  104. int main() {
  105.   ios_base::sync_with_stdio(false);
  106.   cin.tie(NULL);
  107.  
  108.   int t;
  109.   cin >> t;
  110.   while(t --> 0) test();
  111.  
  112.   return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement