my code: #include <cstdio>#include <cstring>#include<iostream>using namespace std;int find(int num,int A []){while(num!=A[num])//{ num = A[num];return num;}// bool follow(int a,int b,int A[]){int i = find(a,A);int j = find(b,A);//cout<…
思路:给定一个无向图,判断有几个联通块. AC代码 #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <utility> #include <string> #include <iostream> #include <map> #include <set> #include <…
题解:1 2,2 3,4 5,是朋友,所以可以坐一起,求最小的桌子数,那就是2个,因为1 2 3坐一桌,4 5坐一桌.简单的并查集应用,但注意题意是从1到n的,所以要减1. 代码: #include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <vector> #includ…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other,…
不想看模板,想直接看题目的请戳下面目录: 目录: HDU 1213 How Many Tables[传送门] HDU 1232 畅通工程 [传送门] POJ 2236 Wireless Network [传送门] POJ 1703 Find them, Catch them [传送门] 先上模板: #define MAXN 根据编号需要 int per[MAXN],rank[MAXN]; void init(int n) { int i; ;i<=n;i++) { per[i]=i;rank[i…
How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14081    Accepted Submission(s): 6912 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinn…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the fri…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13787    Accepted Submission(s): 6760 Problem Description Today is Ignatius' b…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 有关系(直接或间接均可)的人就坐在一张桌子,我们要统计的是最少需要的桌子数. 并查集的入门题,什么优化都无用到就可以直接过.实质上就是统计总共有多少个不相交的集合.比较可恶的是,题目中 There will be a blank line between two cases 是骗人的!!! #include <iostream> using namespace std; + ; int p[…
http://acm.hdu.edu.cn/showproblem.php?pid=1213 题意: 这个问题的一个重要规则是,如果我告诉你A知道B,B知道C,这意味着A,B,C知道对方,所以他们可以留在一个桌子. 例如:如果我告诉你A知道B,B知道C,D知道E,所以A,B,C可以留在一个桌子中,D,E必须留在另一个桌子中.所以Ignatius至少需要2个桌子. 思路: 并查集模板题. #include<iostream> using namespace std; ]; int find(in…