![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
并查集
文章平均质量分 77
Stephaniejx
这个作者很懒,什么都没留下…
展开
-
Find them, Catch them
该题为种类并查集 #include #include using namespace std; #define N 112345 int pre[N]; int Find(int x) { if(x!=pre[x]) pre[x]=Find(pre[x]); return pre[x]; } void mix(int x,int y) { x=Find原创 2017-08-26 15:03:03 · 325 阅读 · 0 评论 -
Farm Irrigation
这题为并查集的联通问题,主要找到能否联通Merge的条件就可以解决 #include #include #include using namespace std; int parent[2600]; struct student{ int up; int left; int down; int right; }node[60][60]; int find(int x){ if(x !=原创 2017-08-26 15:04:26 · 290 阅读 · 0 评论 -
More is better&&The Suspects
这两道题非常相似,都是计算一个联通中所有节点的个数,只需要在find中加个计算就可以了 #include int parent[10000005]; int num[10000005]; int find(int x){ if(x != parent[x]) parent[x] = find(parent[x]); return parent[x]; } void Merge(int a原创 2017-08-26 15:09:47 · 230 阅读 · 0 评论 -
畅通工程
点击打开链接 这道题求得是联通村庄间需要的最小的费用 首先呢,我认为村庄联通不能重叠,意思就是不能成环吧,就是父节点不能一样,接着是用prim算法解决 形成n - 1条边,sort排序 #include #include #include using namespace std; struct student{ int a; int b; int money; }node[1005]原创 2017-08-26 15:12:57 · 281 阅读 · 0 评论 -
01背包,完全背包,多重背包
01背包:有N件物品和一个容量为V的背包,每种物品均只有一件。第i件物品的费用是c[i],价值为V[i]。求解将哪些物品装入装入背包可使价值总和最大 完全背包:有N种物品和一个容量为V的背包,每种物品都可以无限件的使用,第i种物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的费用总和不超过背包的容量,且价值总和最大。 多重背包:有N种物品和一个容量为v的背包,第i种物品原创 2017-08-24 17:17:26 · 324 阅读 · 0 评论