How Many Tables HDU - 1213】的更多相关文章

定义&&概念: 啥是并查集,就是将所有有相关性的元素放在一个集合里面,整体形成一个树型结构,它支持合并操作,但却不支持删除操作 实现步骤:(1)初始化,将所有节点的父亲节点都设置为自己,例如pre[1]=1(2)合并,将一个元素或者一集合(两者间有联系)合并到另外一个集合(元素)里面,谁是谁的父亲节点不需要过多在意,视题意而定.(3)查找,在合并时需要运用到查找操作,即查找该元素的父节点,尽量使用路径压缩,可以使并查集更加高效,一旦使用了路径压缩,查询时就会将该查询元素到父亲的边改为直接连…
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/C 代码: #include<stdio.h> #include<queue> #include<stack> #include<string.h> using namespace std; #define maxn 100…
#include<iostream> using namespace std; ; int p[N]; int find(int x) { if(p[x]!=x) p[x]=find(p[x]); return p[x]; } int main() { int t; int n,m; cin>>t; while(t--) { cin>>n>>m; ;i<=n;i++) p[i]=i; while(m--) { int a,b; cin>>a…
不想看模板,想直接看题目的请戳下面目录: 目录: 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…
题目链接: 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 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,…
题目链接: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…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1213 题意 给出N个人 M对关系 找出共有几对连通块 思路 并查集 AC代码 #include <cstdio> #include <cstring> #include <ctype.h> #include <cstdlib> #include <cmath> #include <climits> #include <ctime&g…
http://acm.hdu.edu.cn/showproblem.php?pid=1213 果然是需要我陪跑T T,禽兽工作人员还不让,哼,但还是陪跑了~ 啊,还有呀,明天校运会终于不用去了~耶耶耶,又可以快乐的玩耍了~ 水一题睡觉~ ------------------------------------------------华丽的分割线------------------------------------------------- 大意: XXX过生日,他要请客.请客的座位安排是认识的…
传送门 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 friends know each other, and all the friends do not want to…
How Many Tables 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/C 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…
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 friends know each other, and all the friends do not want…
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 frie…
解题思路:和畅通工程类似,问最后还剩下几个不连通的区域. How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15086    Accepted Submission(s): 7364 Problem Description Today is Ignatius' birthday. He invites a…
题解: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://blog.csdn.net/dellaserss/article/details/7724401 题意:假设一张桌子可坐无限多人,小明准备邀请一些朋友来,所有有关系的朋友都可以坐同一张桌,没有关系的则要另开一桌,问需要多少张桌子(小明不坐,不考虑小明与其他人的关系)? 思路:常规的并查集.要求出所有人的老大,有几个老大就要几张桌子.那么有关系的都归为同一个老大.用数组实现,再顺便压缩路径. #include <bits/stdc++.h> #define LL…
题目大意:输入两个整数n,m.分别表示点数.对点的操作的次数.在接下来的m行中,每行有两个整数a,b.表示a和b是好朋友.(不是好朋友的不能坐在同一个桌子上) .求需要多少张桌子 解题思路:并查集 1)用total来记录所需要的桌子数.如果没合并一次total就减1. 代码如下: /* * 1213_1.cpp * * Created on: 2013年8月23日 * Author: Administrator */ #include <iostream> using namespace st…
题目链接:hdu1213 赤裸裸的并查集.....水题一个.... #include<stdio.h> #include<string.h> #include<algorithm> #include<queue> #define MAXN 10 using namespace std; int father[1005]; void build(int n) { for(int i = 0 ; i <= n ; i ++) father[i] = i;…
题目大意:有n个人 m行数据,每行数据给出两个数A B,代表A-B认识,如果A-B B-C认识则A-C认识,认识的人可以做一个桌子,问最少需要多少个桌子. 题目思路:利用并查集对相互认识的人进行集合的划分,划分完毕后进行遍历,如果发现一个点的根节点是本身,证明找到一个集合,统计集合数便是答案了. #include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<…
代码: #include<cstdio> #include<cstring> using namespace std; int n,m; int father[1005]; int Find(int a) { int r=a; while(father[a]!=a) { a=father[a]; } father[r]=a; return a; } void Union(int a,int b) { a=Find(a); b=Find(b); if(a!=b) father[b]=…
题目链接: 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): 41546    Accepted Submission(s): 20798 Problem Description Today is Ignatius'…
How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20974    Accepted Submission(s): 10382 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinn…
How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 27812    Accepted Submission(s): 13801 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinn…
How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 27455    Accepted Submission(s): 13656 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinn…
过程模板 扫一下一共有几棵树 输出 #include <iostream> #include <string> #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <map> #include <set> #include <algorithm> #define MAX 1010 using…
简单并查集 #include <cstdio> #include <cstring> #define maxn 30005 int fa[maxn],ans[maxn],n,m; int findd( int x ) { return fa[x] == x ? x : fa[x] = findd(fa[x]); } int main() { //freopen("d://in.txt", "r", stdin); int t; scanf(&…
思路:给定一个无向图,判断有几个联通块. AC代码 #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <utility> #include <string> #include <iostream> #include <map> #include <set> #include <…