贪心+MST——cf1095F】的更多相关文章

开始看错求最短路了.. 但是MST的思路和最短路也差不多 就是先不考虑特殊边,用最小点做一个生成树 然后加入特殊边,进行一次krus即可 #include<bits/stdc++.h> #include<queue> using namespace std; #define maxn 400005 #define ll long long ll s,ans,n,m,a[maxn],Min,tot; ]; int cmp(Edge a,Edge b){return a.w<b.…
题目链接 \(Description\) 有一张\(n\)个点的完全图,每个点的权值为\(a_i\),两个点之间的边权为\(a_i\ xor\ a_j\).求该图的最小生成树. \(n\leq2*10^5,0\leq ai<2^{30}\). \(Solution\) 代码好神啊. 依旧是从高到低考虑每一位.对于当前位i,如果所有点在这一位都为0或1,不需要管(任何边在这一位都为0). 否则可以把点分为两个集合,即i位为0和1的集合,这两个集合间必须存在一条边,且边权这一位只能为1. 考虑怎么高…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5627 题意:Bestcoder的一道题,让你求&意义下的最大生成树. 解法: 贪心,我们从高位到低位贪心,如果含有这一位的边能够构成一棵树的话,我们就可以直接把其他不含有这一位的边全部去掉 然后重复这个行为 这个贪心显然正确啦,至于判断能否构成一颗树,就用并查集就好啦 //HDU 5627 #include <bits/stdc++.h> using namespace std; cons…
怀着很纠结的心情来总结这篇论文,这主要是因为作者提虽然供了源代码,但是我并没有仔细去深究他的code,只是把他的算法加进了自己的项目.希望以后有时间能把MST这一结构自己编程实现!! 论文题目是基于非局部代价聚类(non-local cost aggregation)的立体匹配,从题目上看这篇论文不是局部算法,但是也不是传统意义上的全局算法.这要从基于窗结构局部立体匹配算法说起,如下图: 我们求左右两幅图像在视差d下一点的cost时,我们实际是求得以该点为中心半径为r的Windows内所有点的c…
题目链接: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can…
题目链接: A. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly …
题目链接: A. Bits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Let's denote as  the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given mu…
题目链接: C. Letters Cyclic Shift 题意: 现在一串小写的英文字符,每个字符可以变成它前边的字符即b-a,c-a,a-z这样,选一个字串变换,使得得到的字符串字典序最小; 思路: 贪心,尽量让前边的字典序变小; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #inclu…
题意: 秦始皇要在n个城市之间修路,而徐福声可以用法术位秦始皇免费修1条路,每个城市还有人口数,现要求徐福声所修之路的两城市的人口数之和A尽量大,而使n个城市互通需要修的路长B尽量短,从而使得A/B最大.问A/B最大是多少?(1000个城市) 思路: 老徐可免费修得1条路,那么剩下最多也只需要修n-2条路了,这n-2条路要尽量挑短的,而老徐的那条无所谓长短,只要两城人口尽量多即可.这是没有什么贪心策略的,因为老徐所修之路会影响MST的权值之和的大小.穷举所有城市对要O(n*n),再求次MST需要…
题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was…