
ACM
文章平均质量分 74
Huststephen
Control the code, control the world.
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
并查集入门-hdu 1213
#if 1 #include #include using namespace std; const int MAXN=1005; int parent[MAXN]; int find_set(int x) { //带路径压缩; return parent[x]!=x?parent[x]=find_set(parent[x]):x; } int main() {原创 2017-11-21 19:11:54 · 358 阅读 · 0 评论 -
并查集-HDU 5606
问题:边为0的节点可以联合起来,都算是最亲近的点,例如1到2距离为0,2到3距离为0,则3也是1最亲近的点 距离为1的两点不属于同一棵树(并查集角度的树)。 注意点:边的权重取值为0或者1,而不是从0到1 #if 1 #include #include using namespace std; const int MAXN=100005; int parent[MAXN]原创 2017-11-21 22:18:20 · 288 阅读 · 0 评论 -
并查集 入门-HDU 1232
问题:最少还需要建设多少条道路,使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。 解决方案:相通的路具有相同的根节点。求出有多少棵树,每棵树看成一个节点,为了使这些节点相通,需要(节点数-1)的边。 #include #include using namespace std; const int MAXN=1005; int par原创 2017-11-22 09:15:38 · 239 阅读 · 0 评论 -
二叉索引树-HDU 1166
问题:http://acm.hdu.edu.cn/showproblem.php?pid=1166 解决方案:适合用二叉索引树解决 #include #include #include using namespace std; typedef long long LL; const int MAXN=50005; LL cnum[MAXN]; int lowbit(int原创 2017-11-22 10:06:25 · 294 阅读 · 0 评论 -
尺取法求解HDU 5672
问题:给定字符串string,求解至少有k种字符的子串数目有多少? 解法:前指针j,后指针i,遍历指针i; 当子串的字符种类计数达到k时,可以得到包含该子串的所有子串数(len-i,包括它自身); 递增指针j 若当前子串的字符种类计数仍为k,说明当前子串也是符合题意的,求出原创 2017-11-26 14:05:22 · 421 阅读 · 0 评论