团体程序设计天梯赛-练习集 L2-009. 抢红包
2016-07-06 12:18
405 查看
团体程序设计天梯赛-练习集
L2-009. 抢红包
https://www.patest.cn/contests/gplt/L2-009
简单的模拟,再排序。
L2-009. 抢红包
https://www.patest.cn/contests/gplt/L2-009
简单的模拟,再排序。
#include<iostream> #include <cstdio> using namespace std; bool enemy[105][105]; int pre[105]; int Find(int a) { if (a != pre[a])pre[a] = Find(pre[a]); return pre[a]; } void uion(int a, int b) { int t1 = Find(a), t2 = Find(b); if (t1 != t2)pre[t1] = t2; } void make(int n) { for (int i = 1; i <= n; i++)pre[i] = i; } int main(void) { int n, m, k; scanf_s("%d%d%d", &n, &m, &k); make(n); while (m--) { int a, b, g; scanf_s("%d%d%d", &a, &b, &g); if (g == 1)uion(a, b); else enemy[a][b] = enemy[b][a] = 1; //a和b是敌人 } while (k--) { int a, b; scanf_s("%d%d", &a, &b); int ta = Find(a), tb = Find(b); if (enemy[a][b]) { if (ta == tb)printf("OK but...\n"); else printf("No way\n"); } else { if (ta == tb)printf("No problem\n"); else printf("OK\n"); } } return 0; }
相关文章推荐
- 用XCA(X Certificate and key management)可视化程序管理SSL 证书(2)--生成SSL证书请求
- 使用优先队列实现游戏公告模块(Java)
- tomcat源码解析(三)--请求过程之数据的接收
- 安卓四大控件之Activity详解
- Qt之窗体透明
- Qt之窗体透明
- 冒泡排序, 使用最低票价.---双重循环,一重移动次数.二重移动
- System.Reflection.ReflectionTypeLoadException
- Compare Strings
- 数值的整数次方
- Golang搭建静态服务器- 两行代码搞定
- 使用思维宫殿记忆TCP分层结构
- vs2012 MFC连接及操作access(2007)数据库(ADO)
- 为什么使用sigaction而非signal
- 查询Android UA String
- 根据进程名杀死进程 -kill进程名
- SSO(单点登录)
- each与list的用法
- centos安装gcc
- 省市县json