Files
python/TangDou/XiTi/1295.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

54 lines
1.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int main() {
//cin读入优化
std::ios::sync_with_stdio(false);
//输入+输出重定向
freopen("../1295.in", "r", stdin);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n + 1, vector<int>(n + 1, 0));
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
int v = i % 2 == 0 ? 1 : -1; //偶数为1奇数-1就是说先手的-1后手的1
a[x][y] = v;
//检查比赛是不是已经停止
//只要有一方的 n 个棋子在同一行或者同一列或者同一条对角线上,就是四个方向检查
//行
int r1 = 0;
for (int j = 1; j <= n; j++) {
r1 += a[x][j];
}
//列
int r2 = 0;
for (int j = 1; j <= n; j++) {
r2 += a[j][y];
}
//左上到右下
int r3 = 0;
for (int j = 1; j <= n; j++) {
r3 += a[j][j];
}
//右上到左下
int r4 = 0;
for (int j = 1; j <= n; j++) {
r4 += a[j][n - j + 1];
}
if (r1 == -n || r2 == -n || r3 == -n || r4 == -n) {
cout << i << " milk!" << endl;
return 0;
} else if (r1 == n || r2 == n || r3 == n || r4 == n) {
cout << i << " juice!" << endl;
return 0;
}
}
cout << "drawn!" << endl;
//关闭文件
fclose(stdin);
return 0;
}