AcWing 1250. 格子游戏
原题链接
简单
作者:
1.01
,
2021-04-25 10:39:37
,
所有人可见
,
阅读 295
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<unordered_set>
#include<unordered_map>
using namespace std;
//extern "C"{void *__dso_handle=0;}
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define lowbit(x) x&-x
const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=5e6+10;
const int maxm=100+10;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int f[maxn];
int find(int x) { return x==f[x]?f[x]:f[x]=find(f[x]); }
int n,m;
int get(int x,int y)
{
return x*n+y;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n*m;i++) f[i]=i;
int ans=-1;
for(int i=1;i<=m;i++)
{
int x,y; char op;
cin >> x >> y >> op;
x--,y--;
int a=get(x,y),b;
if(op=='D') b=get(x+1,y);
else b=get(x,y+1);
int fa=find(a),fb=find(b);
if(fa==fb)
{
ans=i;
break;
}
f[fa]=fb;
}
if(ans!=-1) cout << ans << endl;
else cout << "draw" << endl;
}