摘要:此题没有代码,是一道面试题。题目很好理解,有个链表,先判断是否有环,如果有环则求出环的入口。 这道题跟好几位offer收割机讨论过,基本都是已知leetcode或哪里的方法,证明该方法的正确性。 我和我家阳哥,试图证明,策略是可以推导出来的。证明如下: 首先,要判断一个链表是否有环,机智的做法是快慢
阅读全文
摘要:题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4171题意:有n+1个点,这n+1个点由n条边相连,且保证连通。然后给出各个点到出口的距离,要求从0点出发,遍历完n个点后立刻从出口出去。求最少时间。首先,要读懂题意,在遍历过程中不能以校园作为中转。。...
阅读全文
摘要:题目链接:http://poj.org/problem?id=2513思路很容易想到就是判断欧拉通路预处理时用字典树将每个单词和数字对应即可刚开始在并查集处理的时候出错了代码: 1 #include 2 #include 3 #include 4 #include 5 using name...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4099思想很容易想到就是预处理出前10w个的fib数,然后建树查询建树时只用前40位即可,所以在计算时只用截取前60位但是我在截取时总是出错后来看了别人的代码改了一下就对了不过还是不知道为什么那样是对的更...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336很容易想到用kmp这里是next数组的应用定义dp[i]表示以s[i]结尾的前缀的总数那么dp[i]=dp[next[i]]+1;代码: 1 #include 2 #include 3 const ...
阅读全文
摘要:简单的next数组的应用先求出next[n],然后可以在1-next[n]之间枚举长度找出不和前缀和后缀重复的中间的最大长度即可代码: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 #define ma...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1507将i+j为奇数的构成x集合中将i+j为偶数的构成y集合中然后就是构建二部图关键就是构图然后就是简单的求最大匹配代码:
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150很经典的二分题目就是求最小点覆盖集二分图最小点覆盖集=最大匹配数代码: 1 #include 2 #include 3 #include 4 #include 5 #define maxn 110 ...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151求最小路径覆盖二分图最小路径覆盖=点的个数-最大匹配。代码: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6...
阅读全文
摘要:题目链接:二分匹配的应用求最大独立集最大独立集等于=顶点数-匹配数本体中由于男孩和女孩的学号是不分开的,所以匹配数应是求得的匹配数/2代码: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define ...
阅读全文
摘要:题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654将每一行的包含空地的区域编号再将每一列的包含空地的区域编号然后把每一个横向块看作二部图中顶点的集合x中的顶点竖向块看作集合y中的顶点,若两个块有公共的空地,则将他们连...
阅读全文
摘要:题目链接:http://poj.org/problem?id=1125主要是读懂题意然后就很简单了floyd算法的应用代码: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define maxn 110 7...
阅读全文
摘要:题目链接:http://poj.org/problem?id=3159题目很容易理解就是简单的SPFA算法应用刚开始用STL里的队列超时了,自己写了个栈,果断过,看来有时候栈还是快啊。。。。代码: 1 #include 2 #include 3 #include 4 #include 5 #defi...
阅读全文
摘要:题目链接:http://poj.org/problem?id=3169很好的差分约束入门题目,自己刚看时学呢代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #defi...
阅读全文
摘要:题目链接:http://poj.org/problem?id=1847Dijkstra算法的模版应用题意:给你N个点和起点终点,点与点有铁路,接下来的N行分别为点i的情况 第一个数字表示与该点连通的点的个数,接下来给该行的Ki个点,注意第一个所连的点为默认,通过的话不用改扳手,其余的点通过的话要改一...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1272题目就是判断是否连通图及是否存在回路简单的并查集两两合并,如果存在同一个集合,则No如果不是一个连通图 则No否则 Yes代码: 1 #include 2 #include 3 #include 4...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232很简单的并查集了。。。。。。。代码: 1 #include 2 #include 3 using namespace std; 4 const int MAXN=1010; 5 int F[MAXN...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1198简单并查集分别合并竖直方向和水平方向即可代码: 1 #include 2 #include 3 #include 4 #include 5 #define maxn 110 6 using name...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213简单的并查集代码: 1 #include 2 #include 3 #include 4 #include 5 #define maxn 1100 6 using namespace std; 7 ...
阅读全文
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597感觉很不错的区间DP,又做了一遍,感觉自己对边界的处理还是很欠缺代码: 1 #include 2 #include 3 #include 4 #include 5 using namespace s...
阅读全文