当前位置:网站首页>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;}
边栏推荐
猜你喜欢
随机推荐
Go编译原理系列8(变量捕获)
动规(18)-并查集基础题——团伙
考研数一数二数三之间的具体详细区别
ECCV 2022 | Towards Data Efficient Transformer Object Detectors
分布式链路追踪Jaeger + 微服务Pig在Rainbond上的实践分享
Chinese valentine's day of young people crazy to make money, earn 140000 a week
AI 助力双碳目标:让每一度电都是我们优化的
程序猿七夕礼物-如何30分钟给女友快速搭建专属语聊房
第10章 模块和包
Focusing on data sources, data quality and model performance to build a credit profile of small and micro enterprises
244 page PDF!"2022 China cloud computing ecological blue book published
ECCV 2022 | 通往数据高效的Transformer目标检测器
Flutter使用 json_serializable 解析 JSON 最佳方案
抽奖/秒杀/竞价/评分/权威/投票,技术教你用合适的方法做好活动
Analysis and comparison of mobile cross-end technical solutions
集群监控——Zabbix
backbone核心详解系列——RepVGG
微信服务号调用API实现微信报警
聚焦数据来源、数据质量和模型性能构建小微企业信用画像
独立站卖家如何使用 WhatsApp Business API 建立有意义的客户关系?