并查集
ACder_chen
将AC进行到底
展开
-
hdu 1233 还是畅通工程
# include # include # include # include using namespace std; /* 思路: 由于n 个点 n(n-1)/2条边, 所有两边都相互连通, 所以可以用并查集, 首先要按距离排序;后用并查集 在合并集合的过程中 求距离和; */ int bin[105]; int ans; struct p{ int a,b,c;转载 2013-11-02 11:58:52 · 746 阅读 · 0 评论 -
hdu15558(线段相交判定)
#include #include #include using namespace std; #define SIZE 1001 struct point{ double x,y; }line[SIZE][2]; int num[SIZE]; int p[SIZE]; inline bool across(int i,int j) { double原创 2014-04-07 17:12:12 · 628 阅读 · 0 评论 -
HDU3938 Portal 并查集
10 10 10 7 2 1 6 8 3 4 5 8 5 8 2 2 8 9 6 4 5 2 1 5 8 10 5 7 3 7 7 8 8 10 //查询长度 6 1 5 9 1 8 2 7 6#include #include #include #include using namespace std; const int M = 10005;转载 2014-03-24 19:44:54 · 642 阅读 · 0 评论 -
hdu1811
#include #include #include #include #include using namespace std; const int M = 10005; /* 很好的题目, 对于没有等号的关系, 我们只用拓扑排序就能解决, 但是, 对于等于的关系,就不好解决了, 这里用并查集来辅助,当两点相等时 将其合并, 只看本集合的根元素即可, */ struct nod转载 2014-03-24 10:26:08 · 540 阅读 · 0 评论 -
hdu1198 并查集(值得复习)
#include #include #include using namespace std; /* 个人感觉本解法非常好, */ char sign[11][5]={"1010","1001","0110","0101","1100","0011", "1011","1110","0111","1101","1111"}; int Set[100][1转载 2014-03-23 13:24:20 · 598 阅读 · 0 评论 -
poj 1703
#include #include #include using namespace std; const int M = 100005; int Set[M*2]; int n, m; int Find(int x) { return x == Set[x] ? x : Set[x] = Find(Set[x]);原创 2014-03-22 19:56:02 · 557 阅读 · 0 评论 -
hdu1598
#include #include #include #include using namespace std; const int M = 1005; int Set[M]; struct node { int x; int y; int v; }; node s[M]; int n, m; bool cmp(node p1, node p2) {原创 2014-03-22 20:36:15 · 677 阅读 · 0 评论 -
poj 1988
#include #include #include using namespace std; const int M = 30005; int Set[M]; int sum[M]; //记录各点树对应的节点数。 int up[M]; //记录当前节点上面有多少个盒子。 int n, m; void init() { for(int i = 1; i < M; i++)原创 2014-03-22 20:04:28 · 655 阅读 · 0 评论 -
poj2236
#include #include #include #include #include using namespace std; struct node { int x; int y; }s[1005]; int Set[1005]; int vist[1005]; int n; double m; b转载 2014-03-22 19:59:05 · 554 阅读 · 0 评论 -
hdu 1325 Is It A Tree?
#include #include #include using namespace std; const int M = 1005; int vist[M], Set[M]; int du[M]; int a, b, maxn; int flag, cont, k; /* 形成树的条件是, 每一个节点的入度只能为1, 且根只能有一个。 */ int Find(int x) {原创 2014-03-22 19:50:58 · 545 阅读 · 0 评论 -
hdu1272 小希的迷宫
#include #include int set[100001]; int visited[100001]; int find(int x) { int r=x; /* while(r!=set[r]) r=set[r]; return r;*/ return x == set[x] ? x :set[x] = find(set[x]);原创 2014-03-22 19:43:36 · 593 阅读 · 0 评论 -
杭电1829 A Bug's Life
#include #include #include using namespace std; const int M = 4005; int Set[M]; int T, n,m; void init() { for(int i = 1; i <= n*2; i++) { Set[i] = i; } } int Find(int x) {原创 2014-03-22 20:09:44 · 651 阅读 · 0 评论 -
hdu1829向量法
#include #include #include #include #define MAX 100002 using namespace std; int father[MAX],rank[MAX]; void init(int n) { for(int i = 1; i <=n; i ++) father[i] = i; memset(rank,原创 2014-03-22 21:49:51 · 573 阅读 · 0 评论 -
poj1182 食物链
#include #include #include #include using namespace std; const int M = 50005; struct node { int p; int relation; }s[M]; int n, m; int Find(int x) { if(x == s[x].p) return原创 2014-03-22 20:31:30 · 505 阅读 · 0 评论 -
hdu1232 畅通工程
#include #include using namespace std; int n, m; int ans; int Set[1005]; void init() { for(int i = 1; i <= n; i++) { Set[i] = i; } } int Find(int x) { return x == Set[x] ?原创 2013-11-02 11:52:39 · 785 阅读 · 0 评论 -
hdu1879畅通工程
#include #include #include #include using namespace std; /* 本题应该注意的地方, 输入的行数为n*(n-1)/2; 在按值排序时,应把 建好的排前面, 应为不用发钱了; */ int Set[205]; struct node { int x, y; int valu原创 2013-11-02 18:07:52 · 616 阅读 · 0 评论 -
poj3228 Gold Transportation(并查集)值得回顾
题意: 给出n个点,表示有n个原创 2014-10-16 20:05:39 · 539 阅读 · 0 评论