08 2017 档案
摘要:题意:有n个点m条边,求用边把所有点连接起来的最小权值。 题解:当m小于n-1时是不可能的,当有自环时也不可能,排除掉这两个情况然后用Kruskal。 代码: #include <cstdio>#include <algorithm>using namespace std;int n,m,f[110
阅读全文
摘要:题意:有n个村子与很多路,有些路已经修好了,求最小路程把所有村子连起来。 题解:用Kruskal算法,提前把已经修好的路合并。 代码: #include <cstdio>#include <algorithm>using namespace std;int n,q,Map[110][110],f[1
阅读全文
摘要:题意:求连通块中有多少个环。 题解:如果两数的祖先相同则总数加1,否则合并。 代码: #include <cstdio>int pre[2100],sum[2100],tot;int find(int x){ int r = x; while(pre[r] != r){ r = pre[r]; }
阅读全文
摘要:题意:求各个连通块中人数最大的那个并输出。 题解:在join函数里加一个num数组存各个联通块的人数,并找出最大的那个。(要压缩路径) 代码: #include <cstdio>using namespace std;int pre[210000],num[210000],max;int find(
阅读全文
摘要:题目:线段树模板题。 代码: #include <cstdio>#include <algorithm>#include <string>#include <iostream>using namespace std;struct node{ int right,left; int sum;}tree
阅读全文
摘要:题意:给两个字符串s1与s2,让s1循环移位看s2能否能成为s1的子串。 题解:让s1增长一倍,看s2是否是s1的子串。 代码: #include <cstdio>#include <cstring>int next[110000];char a[210000],b[110000];void Get
阅读全文
摘要:题意:输入一个字符串,问长度大于2的所有从首元素开始的子串是否为循环串,是的话循环了几次。 题解:用Kmp算法求出每个i的next【i】,并设t=i-next【i】,if(i%t==0&&i/t>1)。则该子串为循环串并且循环次数为i/t。 代码: #include <string.h>#inclu
阅读全文
摘要:题意:有n个人去三个医生处排队。每个人病情不一样,病情重的先看,如果病情相同则先来后到。 题解:用一个结构体的优先队列,病情优先,病情相同则序号优先。 代码: #include<iostream>#include<functional>#include<queue>#include <string>
阅读全文
摘要:题意:小明开展一个聚会,邀请了n个朋友。认识的朋友才能在一桌(A认识B,B认识C,则C也认识A)。问需要几个桌子。 题解:用并查集求有几个联通块。 代码: #include <cstdio>int pre[1100];int find(int x){ int r = x; while(pre[r]
阅读全文
摘要:题目:给一个矩阵告诉每条边的权,求最小生成树。 题解:建树之后直接用kruskal。 代码: #include <algorithm>#include <iostream>using namespace std;struct node{//每条边的两顶点以及距离 int from; int to;
阅读全文
摘要:题目:给n个点,m条加权边。用最大距离连接所有点。 题解:裸的最大生成树。我用的kruskal。 代码: #include <iostream>#include <algorithm>using namespace std;struct node{//每条边的两顶点以及距离 int from; in
阅读全文
摘要:题意:有n头牛,有m条连接n头牛的路。有一个牛k,所有牛都需要走到牛k处并返回(去的路与回的路距离不同)。求所有牛都最快回到原地处的最大时间。 题解:做这道题的时候,其实并没有想到官方题解。想的是用Dijkstra求出每个牛去和回的最小路相加的最大值。结果用普通的Dijkstra T了。后面用优先队
阅读全文
摘要:hdu终于100题了 嘎嘎嘎嘎嘎 题意:有n个人,一些人认识另外一些人,选取一个集合,使得集合里的每个人都互相不认识,求该集合中人的最大个数。 题解:这题就是求最大独立集,但是这并不是两个集合,而是一个集合,所以求出最大匹配后需要/2,然后代公式:最大独立集=N-最大匹配。最大匹配直接用匈牙利算法求
阅读全文
摘要:题意:有p个课程,n个学生,每个课程有x个学生喜欢。如果每个课程都至少可以分配一个学生就输出YES,否则输出NO。 题解:匈牙利算法裸题。 代码: #include <cstdio>#include <cstring>#define N 400int Map[N][N],S[N],vis[N],n;
阅读全文
摘要:题意:有x个男生各自有喜欢的女生,y个女生各自有喜欢的男生。互相喜欢的在一起有好感度。问怎样好感度最高。 题解:匈牙利算法裸题。 代码: #include <cstdio>#include <cstring>#define N 1500int Map[N][N],M[N],vis[N];int k,
阅读全文
摘要:题意:网络流模板题,求1到n的最大流,直接写模板。 代码: #include <cstdio>#include <algorithm>#include <queue>#include <cstring>#define N 30#define INF 1000000using namespace st
阅读全文
摘要:题意:网络流的裸题,1为源点,n为汇点,给定每条边的容量,求最大流,用EK算法。 代码: #include <cstdio>#include <queue>#include <algorithm>#include <cstring>#define N 300#define INF 0x7ffffff
阅读全文
摘要:C. Leha and Function time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output C. Leha and Functio
阅读全文
摘要:B. Godsend time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output B. Godsend time limit per tes
阅读全文
摘要:模板: //初始化a,因为有last,所以这里无需初始化其他位 a[0]=1; int last=0; for (int i=0;i<K;i++) { int last2=min(last+n[i]*v[i],P);//计算下一次的last memset(b,0,sizeof(int)*(last2
阅读全文
摘要:B. 3-palindrome time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output B. 3-palindrome time limi
阅读全文
摘要:A. Fake NP time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Tavak and Seyyed are good frie
阅读全文

浙公网安备 33010602011771号