POJ 2524】的更多相关文章

http://poj.org/problem?id=2524 题意:在一所学校里面的人,都有宗教信仰,不过他们的宗教信仰有可能相同有可能不同,但你又不能直接去问他们,但你可以问他们和谁是同一个宗教.通过n次询问,求这个学校最多有多少种宗教信仰. 思路:一个并查集的水题.首先假设这个学校的人全都是不同的信仰.然后再去询问,如果两个人的信仰是相同的,合并这两个人且ans--.最后减出来的ans就是答案. #include <stdio.h> #include <iostream> #i…
题目:http://poj.org/problem?id=2524 题意:问一个大学里学生的宗教,通过问一个学生可以知道另一个学生是不是跟他信仰同样的宗教.问学校里最多可能有多少个宗教. 也就是给定一个图的点数和相应的边,问有多少个连通分量. #include<stdio.h> #include<iostream> #include<string.h> using namespace std; ]; int find(int a) { if(bin[a]!=a) ret…
题目地址: http://poj.org/problem?id=2524 题目内容: Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 26119   Accepted: 12859 Description There are so many different religions in the world today that it is difficult to keep tra…
题目链接: http://poj.org/problem?id=2524 Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 39369   Accepted: 18782 Description There are so many different religions in the world today that it is difficult to keep track of…
Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 30666   Accepted: 14860 Description There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in findi…
id=2524">Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23171 Accepted: 11406 Description There are so many different religions in the world today that it is difficult to keep track of them all. You are interested…
Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 23997   Accepted: 11807 Description There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in findi…
Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 20668   Accepted: 10153 Description There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in findi…
//#include<bits/stdc++.h> #include<iostream> #include<stdio.h> #define max1 50005 using namespace std; int pa[max1],vis[max1]; int find(int a) { while(a!=pa[a]) { pa[a]=pa[pa[a]]; a=pa[a]; } return a; } void build(int a,int b) { int fa=f…
并查集思想,初始化每个元素的根节点为本身. 求解目标是求解存在几个集合.解决方案:查看有多少个根节点,表现在记忆数组上就是有多少个元素的根是它本身. #include<stdio.h> #define M 50005 int ji[M]; int findme(int a) { while(ji[a]!=a) { a=ji[a]; } return a; } void link(int a,int b) { int tmp; tmp=b; a=findme(a); b=findme(b); j…