当前位置:网站首页>Motion Rule (16)-Union Check Basic Questions-Grid Game
Motion Rule (16)-Union Check Basic Questions-Grid Game
2022-08-04 12:33:00 【H_Cisco】
[Problem description]
Aliceand Bobplayed an old game: draw one firstn * n lattice (belown= 3) Then, the two of them take turns to draw between adjacent dotsRed and blue borders:
until a closed circle (the area does not have to be 1), the person who "closes" is the winner.Because the board is so big(n<= 200), their game is reallyis too long!They don't even know who won the game in the game.So please write a program to help them figure out if they're over the game?
[input format]
The first line of input data is two integersnandm.mindicates that a total of mlines.After mlines, each line starts with two numbers(x,y), which represents the starting point coordinates of the line, and then separate a character with a space, if the character is"D ", it is a downward connection, if it is "R" is to connect a side to the right.The input data will not have duplicate edges and is guaranteed to be correct.
[Output format]
Output a line: end at the first step.If m does not end after the step, output a line "
[Sample input]
3 5
1 1 D
1 1 R
1 2 D
2 1 R
2 2 D
[Example output]
4
#include #include using namespace std;int fa[40001], n, m, x, y, r1, r2, xx, yy;char ch;int find(int u){return fa[u] == u ? u : fa[u] = find(fa[u]);}int read(){int x = 0;char ch = getchar();while (!isdigit(ch))ch = getchar();while (isdigit(ch))x = x * 10 + ch - 48, ch = getchar();return x;}int main(){cin >> n >> m;for (int i = 1; i <= n * n; i++)fa[i] = i;for (int i = 1; i <= m; i++){x = read();y = read();cin >> ch;xx = n * (x - 1) + y;if (ch == 'D')yy = xx + n;elseyy = xx + 1;r1 = find(xx);r2 = find(yy);if (r1 != r2)fa[r1] = r2;else{cout << i;return 0;}}cout << "draw" << endl;return 0;}
边栏推荐
猜你喜欢
独立站卖家如何使用 WhatsApp Business API 建立有意义的客户关系?
Share | technology integration electronic fence function of scheduling system
【黑马早报】尚乘数科上市13天,市值超阿里;北大终止陈春花聘用合同;新东方花近200亿退学费和遣散费;张小泉75%产品贴牌代工...
他是“中台”之父,凭一个概念为阿里狂赚百亿
Apache Doris 1.1 特性揭秘:Flink 实时写入如何兼顾高吞吐和低延时
TensorFlow学习记录(三):高阶操作 & 神经网络与全连接层
如何让 WPF 程序更好地适配 UI 自动化
正则表达式
Linux-Docker-Mysql安装
集群监控——Zabbix
随机推荐
Nacos手摸手教学【二】Nacos注册中心
AI 助力双碳目标:让每一度电都是我们优化的
考研数一数二数三之间的具体详细区别
Analysis and comparison of mobile cross-end technical solutions
动手学深度学习_LeNet
博云入选 Gartner 中国 DevOps 代表厂商
缓存字符流
企业应当实施的5个云安全管理策略
形态学(膨胀、腐蚀)
获取本机IP地址的脚本
缓存中间件技术选型Memcached、MongoDB、Redis
Go编译原理系列8(变量捕获)
分布式链路追踪Jaeger + 微服务Pig在Rainbond上的实践分享
聚焦数据来源、数据质量和模型性能构建小微企业信用画像
Focusing on data sources, data quality and model performance to build a credit profile of small and micro enterprises
新消费、出海、大健康......电子烟寻找“避风港”
全面认识MOS管,一篇文章就够了
Flutter教程大全合集(2022年版)
WPF---Grid布局讲解
什么是 DevOps?看这一篇就够了!