摘要:
题意:求连通块中有多少个环。 题解:如果两数的祖先相同则总数加1,否则合并。 代码: #include <cstdio>int pre[2100],sum[2100],tot;int find(int x){ int r = x; while(pre[r] != r){ r = pre[r]; } 阅读全文
posted @ 2017-08-21 14:57
LMissher
阅读(187)
评论(0)
推荐(0)
摘要:
题意:求各个连通块中人数最大的那个并输出。 题解:在join函数里加一个num数组存各个联通块的人数,并找出最大的那个。(要压缩路径) 代码: #include <cstdio>using namespace std;int pre[210000],num[210000],max;int find( 阅读全文
posted @ 2017-08-21 14:42
LMissher
阅读(175)
评论(0)
推荐(0)
摘要:
题目:线段树模板题。 代码: #include <cstdio>#include <algorithm>#include <string>#include <iostream>using namespace std;struct node{ int right,left; int sum;}tree 阅读全文
posted @ 2017-08-21 13:54
LMissher
阅读(151)
评论(0)
推荐(0)
摘要:
题意:给两个字符串s1与s2,让s1循环移位看s2能否能成为s1的子串。 题解:让s1增长一倍,看s2是否是s1的子串。 代码: #include <cstdio>#include <cstring>int next[110000];char a[210000],b[110000];void Get 阅读全文
posted @ 2017-08-21 13:50
LMissher
阅读(186)
评论(0)
推荐(0)
摘要:
题意:输入一个字符串,问长度大于2的所有从首元素开始的子串是否为循环串,是的话循环了几次。 题解:用Kmp算法求出每个i的next【i】,并设t=i-next【i】,if(i%t==0&&i/t>1)。则该子串为循环串并且循环次数为i/t。 代码: #include <string.h>#inclu 阅读全文
posted @ 2017-08-21 13:43
LMissher
阅读(137)
评论(0)
推荐(0)
摘要:
题意:有n个人去三个医生处排队。每个人病情不一样,病情重的先看,如果病情相同则先来后到。 题解:用一个结构体的优先队列,病情优先,病情相同则序号优先。 代码: #include<iostream>#include<functional>#include<queue>#include <string> 阅读全文
posted @ 2017-08-21 13:29
LMissher
阅读(219)
评论(0)
推荐(0)
摘要:
题意:小明开展一个聚会,邀请了n个朋友。认识的朋友才能在一桌(A认识B,B认识C,则C也认识A)。问需要几个桌子。 题解:用并查集求有几个联通块。 代码: #include <cstdio>int pre[1100];int find(int x){ int r = x; while(pre[r] 阅读全文
posted @ 2017-08-21 13:21
LMissher
阅读(149)
评论(0)
推荐(0)
摘要:
题目:给一个矩阵告诉每条边的权,求最小生成树。 题解:建树之后直接用kruskal。 代码: #include <algorithm>#include <iostream>using namespace std;struct node{//每条边的两顶点以及距离 int from; int to; 阅读全文
posted @ 2017-08-21 10:41
LMissher
阅读(190)
评论(0)
推荐(0)
摘要:
题目:给n个点,m条加权边。用最大距离连接所有点。 题解:裸的最大生成树。我用的kruskal。 代码: #include <iostream>#include <algorithm>using namespace std;struct node{//每条边的两顶点以及距离 int from; in 阅读全文
posted @ 2017-08-21 10:36
LMissher
阅读(146)
评论(0)
推荐(0)
摘要:
题意:有n头牛,有m条连接n头牛的路。有一个牛k,所有牛都需要走到牛k处并返回(去的路与回的路距离不同)。求所有牛都最快回到原地处的最大时间。 题解:做这道题的时候,其实并没有想到官方题解。想的是用Dijkstra求出每个牛去和回的最小路相加的最大值。结果用普通的Dijkstra T了。后面用优先队 阅读全文
posted @ 2017-08-21 10:31
LMissher
阅读(240)
评论(0)
推荐(0)

浙公网安备 33010602011771号