题目链接: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 果然是需要我陪跑T T,禽兽工作人员还不让,哼,但还是陪跑了~ 啊,还有呀,明天校运会终于不用去了~耶耶耶,又可以快乐的玩耍了~ 水一题睡觉~ ------------------------------------------------华丽的分割线------------------------------------------------- 大意: XXX过生日,他要请客.请客的座位安排是认识的…
题解: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行数据,每行数据给出两个数A B,代表A-B认识,如果A-B B-C认识则A-C认识,认识的人可以做一个桌子,问最少需要多少个桌子. 题目思路:利用并查集对相互认识的人进行集合的划分,划分完毕后进行遍历,如果发现一个点的根节点是本身,证明找到一个集合,统计集合数便是答案了. #include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<…
求连通分量 Sample Input2 //T5 3 //n m1 2// u v2 34 5 5 12 5 Sample Output24 # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <queue> # define LL long long using na…
题目链接: 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 题意: 这个问题的一个重要规则是,如果我告诉你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…
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…
题目链接: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…
题目链接: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;…
题目链接: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…
题目链接: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 简单的并查集 代码: #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #define maxn 1100 using namespace std; int parent[maxn]; int m,n; int Find(int x) { int s; ;s=pa…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1558 解题报告:首先如果两条线段有交点的话,这两条线段在一个集合内,如果a跟b在一个集合内,b跟c在一个集合内,那么a跟c在一个集合内.在一个平面上,有两种操作: P:在这个平面上添加一条线段 Q k:询问添加的第k条线段所在的那个集合有多少条线段 用并查集,然后就是要判断一下线段有没有交点.还有就是题目要求两个test之间要有空行,为此我还PE了一次. #include<cstdio> #inc…
小希的迷宫 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1272 Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房 间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间…
Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, so it's too difficult for Monkey King(WuKong) to gather all of the dragon balls together. His country has N cities and there are exactly N dragon bal…
 本题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1272 Problem Description: 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了房间A和B,那么既可以通过它从房间A走到房间B,也可以通过它从房间B走到房间A,为了提高难度,小希希望任意两个房间有且仅有一条路径可以相通(除非走了回头…
http://acm.hdu.edu.cn/showproblem.php?pid=4496 题意: 给出n个顶点m条边的图,每次选择一条边删去,求每次删边后的连通块个数. 思路: 离线处理删边,从后往前处理变成加边,用并查集维护连通块个数.其实这题和BZOJ 1015差不多. #include<iostream> #include<cstdio> #include<cstring> using namespace std; int n, m, tot, num; ],…
Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3726    Accepted Submission(s): 1415 Problem Description In 12th Zhejiang College Students Games 2007, there was a new stadium built…
http://acm.hdu.edu.cn/showproblem.php?pid=4641 https://blog.csdn.net/asdfgh0308/article/details/40969047 给一个小写字母字符串,1 a表示在字符串尾部添加一个小写字母a,2 表示当前有多少种子串出现次数大于等于K. 求出现次数桶排序(说是拓扑排序也可以?)就阔以了,种类就是t[i].len-t[t[i].f].len. 在线处理是直接扫描,时间复杂度是O(树高*m). 离线做法是先把所有添加操…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2545 树上战争 Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 564    Accepted Submission(s): 305 Problem Description 给一棵树,如果树上的某个节点被某个人占据,则它的所有儿子都被占据,…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 31088    Accepted Submission(s): 16354 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条…
数据分割 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1119    Accepted Submission(s): 268 Problem Description 小w来到百度之星的赛场上,准备开始实现一个程序自动分析系统. 这个程序接受一些形如xi=xj 或 xi≠xj 的相等/不等约束条件作为输入,判定是否可以通过给每个 w 赋…
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 stay with strang…
题目链接: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): 17946    Accepted Submission(s): 8822 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinn…
http://acm.hdu.edu.cn/showproblem.php?pid=3974 题目大意: 一个公司有N个员工,对于每个员工,如果他们有下属,那么他们下属的下属也是他的下属. 公司会给员工安排任务,分配给一个员工后,他也会把这个任务分配给下属.被分配到任务的人立刻停止 当前在做的工作,接受新的任务. 对于给定的M个操作 C x  输出编号为x的任务 T x y  分配任务y给x 思路: 并查集的实现,分配我们只记录在上司结点里,只不过查询的时候要把它的所有上司全部找一遍. #inc…
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=3371 思路: 这道题很明显是一道最小生成树的题目,有点意思的是,它事先已经让几个点联通了.正是因为它先联通了几个点,所以为了判断连通性 很容易想到用并查集+kruskal. 不过要注意 这题有一个坑点,就是边数很多 上限是25000,排序的话可能就超时了.而点数则比较少 上限是500,所以很多人选择用Prim做.但我个人觉得这样连通性不好判断.其实边数多没关系,我们只要去重就好啦,用邻接矩阵存下两点…