mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 13:56:26 +00:00
1250. 格子游戏
https://www.acwing.com/problem/content/submission/code_detail/7072956/
This commit is contained in:
parent
55a83b71b5
commit
8530a5145b
40
AcWing/1250/1250.cpp
Normal file
40
AcWing/1250/1250.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int n, m, x, y, fa[40005], res;
|
||||
char d;
|
||||
|
||||
int get(int x, int y) {
|
||||
return x * n + y;
|
||||
}
|
||||
|
||||
int find(int x) {
|
||||
return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
for (int i = 0; i < n * n; i++) {
|
||||
fa[i] = i;
|
||||
}
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cin >> x >> y >> d;
|
||||
int a = get(--x, --y);
|
||||
int b = d == 'D' ? get(x + 1, y) : get(x, y + 1);
|
||||
int pa = find(a);
|
||||
int pb = find(b);
|
||||
if (pa == pb) {
|
||||
res = i;
|
||||
break;
|
||||
} else {
|
||||
fa[pa] = pb;
|
||||
}
|
||||
}
|
||||
if (!res) {
|
||||
cout << "draw" << endl;
|
||||
} else {
|
||||
cout << res << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user