04 2012 档案

摘要:http://poj.org/problem?id=1511题意:在一个图中,求从1号节点到2-n号节点的最短距离和和从2-n节点到1节点的最短距离和;思路:因为数据太大,用spfa,且要建立双向的;代码:View Code #include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;#define max 1000010#define inf 1000000050stru 阅读全文
posted @ 2012-04-27 22:14 LT-blogs 阅读(247) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1054题意:在一个树中有一些结点,若在一个结点占一个士兵,则和这一节点相邻的结点被控制(包括此节点),求最少需要多少个士兵;思路:用树形dp,num[i][2]数组存储这个结点存在和不存在士兵的情况下子节点所需士兵的最少数目;code:View Code #include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;struct node 阅读全文
posted @ 2012-04-23 20:55 LT-blogs 阅读(230) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1252题意:给出六种钱币(面值都在1-100)求出组合成1-100的最少步数和(这里可以减);思路:完全背包;代码:View Code #include <cstdio>#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>using namespace std;#define mm 9999999int dp1[2100]; //这里刚开始开到200,会WA,要开大一点int a[7] 阅读全文
posted @ 2012-04-13 21:22 LT-blogs 阅读(302) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3184题意:移动奶牛的位置,使相邻两头奶牛的距离满足D或D+1,要注意第一头奶牛在第一个位置,最后一头在最后一个位置,求奶牛的移动步数;思路:滚动数组来记录从第一头奶牛开始所在位置的最小移动步数;代码:View Code #include <cstdio>#include <algorithm>#include <iostream>#include <cstring>using namespace std;#define max 9999999int a[10010] = {0};int s[ 阅读全文
posted @ 2012-04-12 21:24 LT-blogs 阅读(493) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2828题意:在一个队列里,有人依次向第pos个位置插入,求最后的序列;思路:用线段树存储区间内剩余的没有被占的位置,注意插入的时候要从后向前插入;代码:View Code #include <iostream>#include <cstdio>#include <algorithm>#include <cstdlib>#define nn 200010using namespace std;struct node{ int l; int r; int num;}link[8*nn];int p 阅读全文
posted @ 2012-04-08 10:43 LT-blogs 阅读(186) 评论(0) 推荐(0)