#1504. 珅泽教育CSP-J第一轮模拟考第二套 第 33 题
珅泽教育CSP-J第一轮模拟考第二套 第 33 题
第三题
#include<iostream>
int play[3][3] = {0};
int score[3][3];
bool check_row(int i, int role) {
if (play[i][0] != role) return false;
if (play[i][1] != role) return false;
if (play[i][2] != role) return false;
return true;
}
bool check_col(int j, int role) {
if (play[0][j] != role) return false;
if (play[1][j] != role) return false;
if (play[2][j] != role) return false;
return true;
}
bool check_diag(int role) {
if (play[1][1] != role) return false;
if (play[0][0] == role && play[2][2] == role) return true;
if (play[0][2] == role && play[2][0] == role) return true;
return false;
}
bool check(int i, int j, int role) {
return check_row(i, role) || check_col(j, role) || check_diag(role);
}
int adv(int step) {
if (step == 9) return 0;
int role = (step % 2) + 1;
const int inf = 1000000000;
int best = -inf;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (play[i][j] == 0) {
play[i][j] = role;
if (check(i, j, role)) {
best = inf;
}
else {
int test = score[i][j] - adv(step + 1);
if (best < test) {
best = test;
}
}
play[i][j] = 0;
}
}
}
return best;
}
int main() {
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
std::cin >> score[i][j];
int d = adv(0);
if (d > 0)
std::cout << "First Win\n";
else
std::cout << "Second Win\n";
}
关于第一步的走法分析,下列说法正确的是( )。
{{ select(1) }}
- 第一步必须要放置在棋盘的中央位置才能赢下比赛。
- 第一步必须要放置在棋盘的四个角落位置才能赢下比赛。
- 第一步不能选择
score值为负的格子。 - 第一步可以不选中央也可以不选四个角落。