From 8530a5145b4736775ea9da2b2510bf046e6bef1a Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Thu, 12 Aug 2021 11:29:44 +0800 Subject: [PATCH] =?UTF-8?q?1250.=20=E6=A0=BC=E5=AD=90=E6=B8=B8=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/7072956/ --- AcWing/1250/1250.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 AcWing/1250/1250.cpp diff --git a/AcWing/1250/1250.cpp b/AcWing/1250/1250.cpp new file mode 100644 index 00000000..6542fc93 --- /dev/null +++ b/AcWing/1250/1250.cpp @@ -0,0 +1,40 @@ +#include + +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; +}