Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct Game {
- int state[5][5];
- bool diagMajor;
- bool diagMinor;
- bool row[5];
- bool col[5];
- int aRow[5];
- int aCol[5];
- Game() {
- diagMajor = diagMinor = false;
- for(int j = 0; j < 5; j++) row[j] = false;
- for(int j = 0; j < 5; j++) col[j] = false;
- for(int j = 0; j < 5; j++) aRow[j] = false;
- for(int j = 0; j < 5; j++) aCol[j] = false;
- for(int r = 0; r < 5; r++) {
- for(int c = 0; c < 5; c++) {
- state[r][c] = 0;
- }
- }
- }
- bool aliceMove(int t) {
- int r = (t - 1) / 5;
- int c = (t - 1) % 5;
- if(state[r][c] != 0) {
- return false;
- }
- state[r][c] = 1;
- aRow[r]++;
- aCol[c]++;
- return true;
- }
- int moveId(int r, int c) {
- return 5 * r + c + 1;
- }
- int makeMove(int r, int c) {
- if(r == -1) return -1;
- state[r][c] = 2;
- row[r] = true;
- col[c] = true;
- if(r == c) diagMajor = true;
- if(r + c == 4) diagMinor = true;
- return moveId(r, c);
- }
- int bestBobMove() {
- int r = -1, c = -1, score = -1;
- for(int tr = 0; tr < 5; tr++) {
- for(int tc = 0; tc < 5; tc++) {
- if(state[tr][tc] != 0) continue;
- int ts = 0;
- if(not diagMajor) ts += 15 * (tr == tc);
- if(not diagMinor) ts += 15 * (tr + tc == 4);
- ts += 5 * ((not row[tr]) + (not col[tc]));
- ts += max(aRow[tr], aCol[tc]);
- if(ts > score) {
- score = ts;
- r = tr;
- c = tc;
- }
- }
- }
- return makeMove(r, c);
- }
- };
- void test() {
- Game G;
- for(int i = 0; i < 25; i++) {
- int t;
- cin >> t;
- if(not G.aliceMove(t)) continue;
- int u = G.bestBobMove();
- if(u != -1) {
- cout << u << ' ';
- }
- }
- cout << '\n';
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int t;
- cin >> t;
- while(t --> 0) test();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement