【原创】poj ----- 2524 Ubiquitous Religions 解题报告
题目地址:
http://poj.org/problem?id=2524
题目内容:
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 26119 | Accepted: 12859 |
Description
You know that there are n students in your university (0 < n <= 50000). It is infeasible for you to ask every student their religious beliefs. Furthermore, many students are not comfortable expressing their beliefs. One way to avoid these problems is to ask m (0 <= m <= n(n-1)/2) pairs of students and ask them whether they believe in the same religion (e.g. they may know if they both attend the same church). From this data, you may not know what each person believes in, but you can get an idea of the upper bound of how many different religions can be possibly represented on campus. You may assume that each student subscribes to at most one religion.
Input
Output
Sample Input
10 9
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
10 4
2 3
4 5
4 8
5 8
0 0
Sample Output
Case 1: 1
Case 2: 7
Hint
Source
#include <stdio.h> int set[];
int n,m; int find_father(int son)
{
if (set[son] == ) {
return son;
}
return set[son] = find_father(set[son]);
} void init()
{
for (int i = ; i < n; i ++) {
set[i] = ;
}
} int main(void)
{
int count = ;
int man1,man2;
while (scanf("%d%d", &n, &m)) {
if (m == && n == )
break;
int res = n;
for (int i = ; i < m; i ++) {
scanf("%d%d", &man1, &man2);
int fat1 = find_father(man1);
int fat2 = find_father(man2);
if (fat1 != fat2) {
set[fat2] = fat1;
res --; // 合并一次,减少一个集合
}
}
printf("Case %d: %d\n", count, res);
init();
count ++;
}
return ;
}
【原创】poj ----- 2524 Ubiquitous Religions 解题报告的更多相关文章
- POJ 2524 Ubiquitous Religions 解题报告
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 34122 Accepted: ...
- POJ 2524 Ubiquitous Religions
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 20668 Accepted: ...
- poj 2524 Ubiquitous Religions(宗教信仰)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 30666 Accepted: ...
- [ACM] POJ 2524 Ubiquitous Religions (并查集)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23093 Accepted: ...
- poj 2524:Ubiquitous Religions(并查集,入门题)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23997 Accepted: ...
- poj 2524 Ubiquitous Religions 一简单并查集
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 22389 Accepted ...
- poj 2524 Ubiquitous Religions(并查集)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23168 Accepted: ...
- POJ 2524 Ubiquitous Religions (幷查集)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23090 Accepted: ...
- poj 2524 Ubiquitous Religions (并查集)
题目:http://poj.org/problem?id=2524 题意:问一个大学里学生的宗教,通过问一个学生可以知道另一个学生是不是跟他信仰同样的宗教.问学校里最多可能有多少个宗教. 也就是给定一 ...
随机推荐
- Servlet API中文版
基本类和接口 一.javax.servlet.Servlet接口 servlet抽象集是javax.servlet.Servlet接口,它规定了必须由Servlet类实现由servlet引擎识别和管理 ...
- 【夯实基础】Spring在ssh中的作用
尊重版权:http://blog.csdn.net/qjlsharp/archive/2009/03/21/4013255.aspx 写的真不错. 在SSH框假中spring充当了管理容器的角色.我们 ...
- SMART原则_百度百科
SMART原则_百度百科 SMART原则
- Oracle12C 怎样导入scott用户
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaG9uZ2thbmd3bA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Eclipse乱码怎么办
Eclipse里设置编码有三个层次:全局.工程.文件. 文件的编码会覆盖工程的编码,工程的编码会覆盖全局的编码. 我猜测:虽然你的工程编码更改为GBK,但只对新建文件有效. 如果工程中旧有的文件是UT ...
- RH033读书笔记(17) - Summary
End of Unit 1 • Questions and Answers • Summary • Open source and the right to modify • The GNU Proj ...
- 用N2N搭建简单的VPN
1. 概述 N2N是一款开源的P2P VPN软件,其作者是著名的开源网管软件ntop的作者Luca Deri. N2N是一个双层架构的VPN,它让用户能够在网络层上开发P2P应用的典型功能,而不是 ...
- JavaScript2谁刚开始学习应该知道4最佳实践文章(翻译)
原版的:24 JavaScript Best Practices for Beginners (注:阅读原文的时候没有注意公布日期,觉得不错就翻译了,翻译到JSON.parse那一节觉得有点不正确路才 ...
- 解决SQL查询总是超时已过期
解决SQL查询总是超时已过期 .在WIN8里提示:OLE DB 或 ODBC 错误 : 查询超时已过期; HYT00 1.由于数据库设计问题造成SQL数据库新增数据时超时 症状: Microso ...
- Tutorial: 结合使用AngularJS和Django
好吧,我承认自己很懒,时间又不够用. 翻译的几个文章都是虎头蛇尾,但我保证这次肯定不太监. 关键的单词不翻译,实在觉得翻译成汉语很别扭,括号里是参考翻译. 有问题和建议尽管提出来,我会改进完善. Tu ...