POJ2524——Ubiquitous Religions】的更多相关文章

Ubiquitous Religions 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 finding out how many different religions students in your university believe in. You know…
题目链接 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…
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…
http://poj.org/problem?id=2236 由于发生了地震,有关组织组把一圈电脑一个无线网,但是由于余震的破坏,所有的电脑都被损坏,随着电脑一个个被修好,无线网也逐步恢复工作,但是由于硬件的限制,一台电脑和另一台电脑能够相连当他们之间的距离小于d,或者还有一台电脑当中介,分别与两台电脑相连. 在修复的过程中,工作者会有两种操作,修复电脑和询问电脑a和电脑b是否相连.当询问的时候输出答案. 因为输入数据很大,需要快速判断电脑a和电脑b相连,所以自然想到用并查集. 初始时候 全部电…
题目链接. 分析: 给定 n 个点和 m 条无项边,求连通分量的数量.用并查集很简单. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <map> #include <queue> #include <cmath> using namespace s…
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…
Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 26678   Accepted: 13127 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: 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…
题目地址: 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…
Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 34122   Accepted: 16477 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: 23093   Accepted: 11379 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: 22389   Accepted: 11031 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 fin…
Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 23168   Accepted: 11404 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: 23090   Accepted: 11378 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…
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 finding out how many different religions students in your university believe in. You know that there are n stud…
并查集. #include<cstdio> #include<cstring> using namespace std; const int maxn = 55555; int fa[maxn]; int vis[maxn]; int n,m,t; void init(){ for(int i = 0; i < n; i++) {fa[i] = i;} memset(vis,0,sizeof(vis)); } int find_father(int u){ return fa…
//#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…
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 finding out how many different religions students in your university believe in. You know that there are n stud…
Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 32364 Accepted: 15685 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 finding out how many different…
Description 当今世界有很多不同的宗教,很难通晓他们.你有兴趣找出在你的大学里有多少种不同的宗教信仰. 你知道在你的大学里有n个学生(0 < n <= 50000) .你无法询问每个学生的宗教信仰.此外,许多学生不想说出他们的信仰.避免这些问题的一个方法是问m(0 <= m <= n(n - 1)/ 2)对学生, 问他们是否信仰相同的宗教( 例如他们可能知道他们两个是否去了相同的教堂) .在这个数据中,你可能不知道每个人信仰的宗教,但你可以知道校园里最多可能有多少个不同的…
题意:有编号为1到n的学生,然后有m组调查,每组调查中有a和b,表示该两个学生有同样的宗教信仰,问最多有多少种不同的宗教信仰 简单并查集 //#define LOCAL #include <iostream> #include <cstdio> #include <cstring> using namespace std; + ; int parent[maxn], n, m; int GetParent(int x) { return parent[x] == x ?…
题目: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 这道题就是并查集. #include<cstdio> #include<cstring> #include<iostream> #define maxn 50010 using namespace std; int a[maxn]; int n,m; void init() { ;i<=n;i++) a[i]=i; } int find1(int x) { if(x!=a[x]) a[x]=find1(…
Description 当今世界有很多不同的宗教,很难通晓他们.你有兴趣找出在你的大学里有多少种不同的宗教信仰.你知道在你的大学里有n个学生(0 < n <= 50000).你无法询问每个学生的宗教信仰.此外,许多学生不想说出他们的信仰.避免这些问题的一个方法是问m(0 <= m <= n(n - 1)/ 2)对学生, 问他们是否信仰相同的宗教( 例如他们可能知道他们两个是否去了相同的教堂) .在这个数据中,你可能不知道每个人信仰的宗教,但你可以知道校园里最多可能有多少个不同的宗教…
解题思路:输入总人数 n,和m组数据:即和杭电畅通工程相类似,对这m组数据做合并操作后,求最后一共有多少块区域. #include<stdio.h> int pre[50001]; int find(int root) { if(root!=pre[root]) pre[root]=find(pre[root]); return pre[root]; } void unionroot(int x,int y) { int root1,root2; root1=find(x); root2=fi…
对与知道并查集的人来说这题太水了,裸的并查集,如果你要给别人讲述并查集可以使用这个题当做例题,代码中我使用了路径压缩,还是有一定优化作用的. #include <stdio.h> #include <string.h> const int maxn = 500005; int n, m; int pa[maxn]; void init() { for (int i = 1; i <= n; i++) { pa[i] = i; } } int find(int x) { if…
C - Ubiquitous Religions Time Limit: 5000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main Description There are so many different religions in the world today that it is difficult to keep track of them all. You…
Ubiquitous Religions Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Description 当今世界有很多不同的宗教,很难通晓他们.你有兴趣找出在你的大学里有多少种不同的宗教信仰. 你知道在你的大学里有n个学生( < n <= ) .你无法询问每个学生的宗教信仰.此外,许多学生不想说出他们的信仰.避免这些问题的一个方法是问m( <= m <= n(n - )/ )对学…