当前位置:网站首页>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;} 边栏推荐
- MOSFET米勒平台(Miller Plateau)
- AI 助力双碳目标:让每一度电都是我们优化的
- 缓存字符流
- COVID-CT新冠肺炎检测(DenseNet网络)
- backbone核心详解系列——RepVGG
- Tarjan 求有向图的强连通分量
- C#控制台退出前操作
- ECCV 2022 | Towards Data Efficient Transformer Object Detectors
- 如何做好企业数字化转型?这10份靠谱案例收藏了(附下载)
- UMA & Hong Kong Polytechnic & Ali propose SP-ViT to learn 2D space prior knowledge for visual Transformer!
猜你喜欢
随机推荐
Practical sharing of distributed link tracking Jaeger + microservice Pig on Rainbond
考研概率论与数理统计(知识点梳理)
聚焦数据来源、数据质量和模型性能构建小微企业信用画像
MOSFET米勒平台(Miller Plateau)
Based on the BiLSTM regression forecast method
Apache Doris 1.1 特性揭秘:Flink 实时写入如何兼顾高吞吐和低延时
监督和半监督学习下的多标签分类综述
抗积分饱和PID控制器
LeetCode Daily Question (858. Mirror Reflection)
【UML】信息系统分析与设计知识点总结
小程序在政务服务平台建设中如何发挥价值
企业应当实施的5个云安全管理策略
[牛客网]OR63删除公共字符
拥有一台服务器,程序猿装X的开始
移动跨端技术方案分析对比
七夕疯狂搞钱的年轻人,一周赚14万
考研数一数二数三之间的具体详细区别
飞书更新招聘功能 候选人可选择面试时间
接到“网站动态换主题”的需求,我是如何踩坑的
exness:美联储重现鹰派口吻,黄金承压面临转跌信号









