摘要:转载一篇博客:http://www.cnblogs.com/ylfdrib/archive/2010/11/03/1867901.htmlTarjan实现: dfs + 并查集;通过这道题体会一下把:(思路详见上面的博客)hdu 2586 http://acm.hdu.edu.cn/showproblem.php?pid=2586 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 1...
阅读全文
摘要:http://acm.cs.ecnu.edu.cn/problem.php?problemid=2518题意:给出一张图,求出其hilltop的个数。hilltop的定义:一片相同高度的区域,而周围的区域的高度都小于它,或处于图的边缘。周围的区域:与某片区域高度不相同的区域,且范围是向八个方向延伸。DFS搜索某个点,并记录,搜索周围八个方向,若有一个点大于它则这块区域不是HILLTOP。标记周围所有与它高度相同的点防止重复搜索。 1 #include 2 #include 3 #include 4 using namespace std; 5 int mat[105][75]; 6 bool
阅读全文
摘要:http://acm.cs.ecnu.edu.cn/problem.php?problemid=2064大致题意:给出一些物品的体积与体积上限,选出一些物品,使得物品总体积大于等于体积上限且差值最小,求出这个差值n 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #include12 #include13 #include14 #include15 #include16 using namespace std;17 int a[21],nex
阅读全文
摘要:http://acm.cs.ecnu.edu.cn/problem.php?problemid=1853题意,从图的左上角走到图的右下角,寻找一条路径使得路径上的数字的MAX-MIN最小(不在意路径的长度)直接DFS剪枝比较难写(也感觉要T),看到差值最大为110,用二分枚举了差值(MAX-MIN)(从0到110),再枚举了图上的最小值。大意就是,先二分枚举差值m,再枚举图中可能的最小值a(从真·最小值到真·最大值),min=a,max=a+m。接着对起点DFS,看能否在min 2 #include 3 #include 4 #include 5 #include 6 #i
阅读全文
摘要:EOJ 2113 http://acm.cs.ecnu.edu.cn/problem.php?problemid=2113题意:背包问题,注意到N很小30,V很大10^7,故用dfs。简单的dfs——O(2^N),这里需用剪枝。引用背包九讲:基本的剪枝方法不外乎可行性剪枝或最优性剪枝。1.可行性剪枝即判断按照当前的搜索路径搜下去能否找到一个可行解,例如:若将剩下所有物品都放入背包仍然无法将背包充满(设题目要求必须将背包充满),则剪枝。2.最优性剪枝即判断按照当前的搜索路径搜下去能否找到一个最优解,例如:若加上剩下所有物品的权值也无法得到比当前得到的最优解更优的解,则剪枝。这题用2.最优性剪枝。
阅读全文
摘要:EOJ 1087http://acm.cs.ecnu.edu.cn/problem.php?problemid=1087POJ 1383题意:参看了别人的思路,此题无环,即树的最长路。 思路来自以下链接,写的很好,我就不献丑了。 http://blog.csdn.net/nvfumayx/article/details/7540465贴个代码: 1 //poj 1383 2 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #define MAXN 100510 11 using nam...
阅读全文
摘要:没什么营养的DFS,主要是为了好玩第一次尝试写文件离线打表(其实没意义)输出的总文件长度大概20几k.. 1 #include<map> 2 #include<queue> 3 #include<cmath> 4 #include<cctype> 5 #include<cstdio> 6 #include<string> 7 #include<cstdlib> 8 #include<cstring> 9 #include<iostream>10 #include<algorithm
阅读全文
摘要:http://acm.cs.ecnu.edu.cn/problem.php?problemid=1148题意:在n*n的矩阵中填入1-n^2,使得任意两个相邻的数字之和为质数,并且输出符合条件的最小序列(就是指小数尽量在前)。dfs,从小数开始填,从左到右,从上到下的方法进行搜索,可以使得判断条件仅考虑与上面数字的和以及左面数字的和为质数,并且以此方法第一个填完的表即是最小序列。但方法依然比较朴素,故tle,无奈打表。由于tle,仅提供思路 1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio&g
阅读全文
摘要:EOJ 1199: http://acm.cs.ecnu.edu.cn/problem.php?problemid=1199poj 1256: http://poj.org/problem?id=1256题意不难理解: 给定一个字符串,让你完成:全排列+去重+排序; 最坑的是排序:poj 中有说明: hint: An upper case letter goes before the corresponding lower case letter. So the right order of letters is 'A'<'a'<'B'
阅读全文
摘要:http://acm.cs.ecnu.edu.cn/problem.php?problemid=2859简单dfs。但花了比较大的精力去处理不添加符号的情况,求出所有的情况复杂度大概是8*3^8,最后用map匹配完成dfs遍历时存下添加符号的方法,到最终再计算处理会比较清晰。用hash可能更快。 1 #include<map> 2 #include<cmath> 3 #include<queue> 4 #include<cctype> 5 #include<cstdio> 6 #include<string> 7 #inc
阅读全文