摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2063View Code 1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 const int MAX = 1500 + 10; 5 vector <int> v[MAX]; 6 int link[MAX]; 7 int used[MAX]; 8 bool FindPath(int num) 9 {10 int len = v[num].size();11 int i;12 for(i=0; 阅读全文
posted @ 2012-11-03 12:02 zx雄 阅读(237) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1251字典上的结构为字典树的模版题用了指针的指针注意理解 **Q 的意思//View Code 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 struct Node 5 { 6 int n; 7 Node *child[26]; 8 }; 9 void NewNode(Node **Q)//注意这里使用了指针的指针10 {11 (*Q) = (Node *)malloc(sizeof(Node)). 阅读全文
posted @ 2012-10-20 16:40 zx雄 阅读(386) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2844多重背包问题.求出恰好能买的数目.最后找f[i]>0的背包有几个或者不需要恰好装满,最后搜索f[i] == i 的数目//背包模版 1 #include <iostream> 2 using namespace std; 3 const int MAX = 100000 + 10; 4 const int INF = 0x7fffffff; 5 int f[MAX]; 6 int v; 7 void ZeroOnePack(int cost,int weight) 8 { 9 int 阅读全文
posted @ 2012-09-12 16:32 zx雄 阅读(1010) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2647题意:老板想要用最少的钱给所有人发奖金,每个人最少888元,但由于有人的奖金有比别人多,要求求出最少的奖金.输入:第一行两个数字n,m m表示人数 m表示接下有m行输入. 输入m组 a b 表示a的奖金要比b的多.输出:输出最少的奖金数. 如果不可能求出,输出-1用的书拓扑排序.由于要用最少的钱的完成.所以不能直接用拓扑排序一找到入度为0的点,必须进行一些变形.否则会出现错误.在遍历每个点时,先找到1,1的奖金为888.正确接下来遍历时,遍历到2,无法判断2应该发多少钱.用了两种方法做.两种方法都是.. 阅读全文
posted @ 2012-09-10 15:43 zx雄 阅读(698) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1228只是A+B 输出结果,用了STL中的map 和 reverse()函数//View Code 1 #include <iostream> 2 #include <map> 3 #include <string> 4 #include <algorithm> 5 using namespace std; 6 int main() 7 { 8 map <string , int > m; 9 string str;10 m["one&qu 阅读全文
posted @ 2012-09-08 19:57 zx雄 阅读(187) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1160题意:要求找出老鼠体重递增,速度递减的最长子序列(不需要连续).输入到文件尾结束.输入完后再处理数据.有可能出现多种情况.满足一种即可.-------->用结构体记录体重和速度因有两个要求,所以要进行排序.我是按老鼠体重升序排序.排序时序号会乱.所以要记录编号.定义数组father[]记录子串个数.找的时候找到符合条件的.(体重递增,速度减少)记录他为前面记录最大的+1;(father[i] < father[j] + 1)并记录MAX的值.最后从MAX的位置向前查找.丢入栈中.最后出栈输出 阅读全文
posted @ 2012-09-07 21:34 zx雄 阅读(269) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1257用贪心的思想,每一个系统尽可能多的去拦截导弹.//View Code 1 #include <iostream> 2 #include <algorithm> 3 #include <stack> 4 using namespace std; 5 const int MAX = 1000 + 10; 6 const int INF = 0x3fffffff; 7 struct Mouse 8 { 9 int fat;10 int speed;11 int num;12 阅读全文
posted @ 2012-09-07 21:02 zx雄 阅读(226) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1162输入一个整数n,表示点的个数.接下来n行,每行有两个浮点数表示点的x坐标y坐标.构造一棵最小生成树.用Kruskal做.先算出各条边的权值.再合并//View Code 1 #include <iostream> 2 #include <algorithm> 3 #include <cmath> 4 using namespace std; 5 const int MAX = 10000 + 10; 6 const int INF = 0x3fffffff; 7 in 阅读全文
posted @ 2012-09-06 21:01 zx雄 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 初始化的细节问题我们看到的求最优解的背包问题题目中,事实上有两种不太相同的问法。有的题目要求“恰好装满背包”时的最优解,有的题目则并没有要求必须把背包装满。一种区别这两种问法的实现方法是在初始化的时候有所不同。如果是第一种问法,要求恰好装满背包,那么在初始化时除了f[0]为0其它f[1..V]均设为-∞,这样就可以保证最终得到的f[N]是一种恰好装满背包的最优解。如果并没有要求必须把背包装满,而是只希望价格尽量大,初始化时应该将f[0..V]全部设为0。为什么呢?可以这样理解:初始化的f数组事实上就是在没有任何物品可以放入背包时的合法状态。如果要求背包恰好装满,那么此时只有容量为0的背包可能被 阅读全文
posted @ 2012-09-06 19:42 zx雄 阅读(231) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2066用来练习SPFA有多个出发点事不必做多次的SPFA,只要把多个顶点初始化为0即.//View Code 1 #include <iostream> 2 #include <algorithm> 3 #include <queue> 4 using namespace std; 5 const int MAX = 1100; 6 const int INF = 0x3fffffff; 7 int map[MAX][MAX]; 8 int start[MAX]; 9 in 阅读全文
posted @ 2012-09-05 09:59 zx雄 阅读(551) 评论(0) 推荐(0) 编辑