POJ2524-宗教问题-并查集-ACM】的更多相关文章

题目链接. 分析: 给定 n 个点和 m 条无项边,求连通分量的数量.用并查集很简单. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <map> #include <queue> #include <cmath> using namespace s…
Time limit5000 ms Memory limit65536 kB There are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your university believe in. You…
太难的搞不过,只能来写简单的了 POJ2524 无所不在的宗教 世界上宗教何其多.假设你对自己学校的学生总共有多少种宗教信仰很感兴趣.学校有n个学生,但是你不能直接问学生的信仰,不然他会感到很不舒服的.有另外一个方法是问m对同学,是否信仰同一宗教.根据这些数据,相信聪明的你是能够计算学校最多有多少种宗教信仰的. [输入格式] 可以输入多个测试用例(Case),每一个用例的第一行包含整数n和m,n表示学生编号(1-n),在接下来的m行中,每一行包含两个整数,对应信仰同一宗教的两名学生的编号,输入结…
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>using namespace std;int n,m;int bin[50001];int findx(int x){    int r=x;    while(r!=bin[r])        r=bin[r];    int j=x,k;    while(j!=r)    {        k=bin…
题目链接 http://poj.org/problem?id=2524 题意 有n个学生,编号1~n,每个学生最多有1个宗教信仰,输入m组数据,每组数据包含a.b,表示同学a和同学b有相同的信仰,求在n名学生中最多存在多少种不同的宗教信仰. 思路 使用并查集解决. 代码 #include <iostream> #include <cstring> #include <cstdio> using namespace std; + ; int p[N]; void make…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 Problem Description Given an undirected connected graph G with n nodes and m edges, with possibly repeated edges and/or loops. The stability of connectedness between node u and node v is defined by…
题目链接:http://poj.org/problem?id=2524 题目大意:学校共有n个同学,告诉你m对同学信仰同一宗教,问这个学校学生信仰宗教的数目最多为多少. 例: Sample Input 10 91 21 31 41 51 61 71 81 91 1010 42 34 54 85 80 0 Sample Output Case 1: 1Case 2: 7 解题思路:直接套并查集的板子就可以了,初始化n个集合默认他们都信任不一样的宗教,初始就用n个宗教,每次给你的两个同学那个号码将他…
时间限制(普通/Java):5000MS/15000MS     内存限制:65536KByte 描述 NKU ACM最近要举行足球赛,作为此次赛事的负责人,Lee要对报名人员进行分队.分队要遵循如下原则: 一个人不能加入多支队伍:不认识的人不能分在同一队:如果a和b认识,b和c认识,那么认为a和c也认识:每支队伍上限8人,下限5人:尽量使队伍满员.由于参赛人数很多,Lee表示无能为力,所以请你帮助Lee编程解决比赛有多少队伍. 输入 第一行输入两个整数,n和m,n(1<=n<=300000)…
ACM数据结构-并查集   并查集,在一些有N个元素的集合应用问题中,我们通常是在开始时让每个元素构成一个单元素的集合,然后按一定顺序将属于同一组的元素所在的集合合并,其间要反复查找一个元素在哪个集合中.这一类问题近几年来反复出现在信息学的国际国内赛题中,其特点是看似并不复杂,但数据量极大,若用正常的数据结构来描述的话,往往在空间上过大,计算机无法承受:即使在空间上勉强通过,运行的时间复杂度也极高,根本就不可能在比赛规定的运行时间(1-3秒)内计算出试题需要的结果,只能用并查集来描述. 并查集是…
F. Palindrome Problem Description A string is palindrome if it can be read the same way in either direction, for example "maram" is palindrome, while "ammar" is not. You are given a string of n characters, where each character is eithe…