摘要: 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 阅读(227) 评论(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 阅读(204) 评论(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 阅读(271) 评论(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 阅读(465) 评论(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 阅读(168) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1840题意:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 ,给出a1,a2,a3,a4,a5,且xi在-50到50(除零外),有多少种满足条件的组合;思路:用hash,这里有两种,一种用map建立,不过我刚开始超时了,后来发现 for (i = -50; i <= 50; i++) x[m++] = i * i * i; 先这样处理下就行了,不过时间还是挺长的,另一种就是普通的hash了,这里我用的静态加挂链的方式;代码:View Code #include <cstdio>#include &l 阅读全文
posted @ 2012-03-30 21:07 LT-blogs 阅读(152) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2442题意:给出m个序列,每个序列有n个数,从每个序列中选择一个数相加,总共有n^m个数,输出这些数中最小的n个数;思路:用的是stl中的heap(堆)从上到下层层维护堆,堆的复杂度为nlogn;代码:View Code #include <cstdio>#include <iostream>#include <algorithm>using namespace std;int a[2010] = {0};int b[2010] = {0};int heap[2010] = {0};int main(){ 阅读全文
posted @ 2012-03-26 20:42 LT-blogs 阅读(358) 评论(2) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1035题意:给出一些字典单词,然后给出查询的单词temp,若字典单词中有temp就直接输出,如果没有就输出1:一个字母拼写错误;2:多添加了 一个字母;3:少了一个字母;思路:用vector存的string序列,然后用string的一些特性来判断的;代码:View Code #include <cstdio>#include <string>#include <cstring>#include <iostream>#include <cstdlib>#include <vec 阅读全文
posted @ 2012-03-25 16:07 LT-blogs 阅读(247) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2939题意:但某个人点到两次时这个人自杀,当某个人点到三次时,循环结束,求结束时剩余的人数;思路:用哈希写,经典的题啊;(代码是参考其他队友的)代码:View Code #include <iostream>#include <cstdio>#include <algorithm>#define inf 1000009using namespace std;struct node{ long long data; int num; int next;}node[inf];int link[inf];lon 阅读全文
posted @ 2012-03-25 10:58 LT-blogs 阅读(254) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2418题意:给定一些树,按字典序输出数名和树出现的频率;思路:这个题用二叉搜索树可以做,同时在网上看到了一个简单的方法,用map来做,这里map真是太好用了;map做法:View Code #include <iostream>#include <map>#include <cstdio>#include <string>using namespace std;int main(){ string a; map<string,int>tree; double n = 0; char 阅读全文
posted @ 2012-03-23 19:26 LT-blogs 阅读(184) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2513题意:有一些棒子,每一根的两头都有两个颜色,将这些棒子相连并且被两根棒子接头处是相同的颜色,求一些这样的棒子是否都可以全部连起来;思路:首先用tree树给每一种颜色编号,然后用并查集+欧拉路(只有两个或零个奇数结点);代码:View Code #include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;int f[500010] = {0};int n = 0;in 阅读全文
posted @ 2012-03-22 23:59 LT-blogs 阅读(178) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1094感觉还是挺好的一个题的,虽说是看的小媛的思路;题意:判断给出的一些字母的先后顺序,进行拓扑排序,看看是否有序;思路:用flord判断环还是挺好的,然后拓扑排序判断序列的排序关系;代码:View Code #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>using namespace std;int n = 0;int m = 0;int ma 阅读全文
posted @ 2012-03-17 00:23 LT-blogs 阅读(207) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3026题意:在一个y行 x列的迷宫中,有可行走的通路空格’ ‘,不可行走的墙’#’,还有两种英文字母A和S,现在从S出发,要求用最短的路径L连接所有字母,输出这条路径L的总长度;思路:用bfs找出每两个点之间的距离,然后用prim求出最小生成树;思路是参考网上的;代码:View Code #include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <queue>using name 阅读全文
posted @ 2012-03-16 15:03 LT-blogs 阅读(198) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3041View Code #include <iostream>#include <cstdio>#include <cstring>using namespace std;int map[510][510] = {0};int match[510] = {0};int value[510] = {0};int n = 0;int m = 0;int x = 0;int y = 0;int find(int q){ for(int i = 1;i <= n; ++i) { if(value[i] = 阅读全文
posted @ 2012-03-14 22:13 LT-blogs 阅读(141) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1273题意:有一些流水的水沟,求从起点1到达终点的最大水量,每条水沟都有一个最大流水量;思路:基础的网络流问题(EK算法),注意边的重复;View Code #include <iostream>#include <cstdio>#include <cstring>#include <queue>#define max 205using namespace std;int s[max][max] = {0};int n = 0;int m = 0;int a = 0;int b = 0;int 阅读全文
posted @ 2012-03-11 15:45 LT-blogs 阅读(150) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1062题意:一个人想娶酋长的女儿,酋长有个条件,就是用金币或者是用物品和少量的金币来交换,其他拥有物品的人亦可以用同样方法来交换;思路:dijkstra+枚举,思路是从网上看的,题目中的“地位较高的的人不会再和他交易”其实挺干扰人的,没有用到这个;代码:View Code #include <cstdio>#include <iostream>#include <cstdlib>#include <algorithm>#include <cstring>using namespac 阅读全文
posted @ 2012-03-06 21:15 LT-blogs 阅读(165) 评论(0) 推荐(0) 编辑
摘要: http://acm.tju.edu.cn/toj/showp3017.htmlhttp://acm.sdut.edu.cn/web/problem.php?action=showproblem&problemid=2384思路:dp题,自己脑子太笨了,代码如下,提醒一下自己;View Code #include <iostream>#include <cstdio>#include <string>#include <cstring>using namespace std;int s[110] = {0};int n = 0;int m 阅读全文
posted @ 2012-03-04 20:42 LT-blogs 阅读(172) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3083题意:迷宫问题,求从进入点到出口,分别按靠左边,右边和最短距离到达出口所学要的步数;思路:用dfs求得靠左靠右走到达出口的步数,用bfs求最短最少到达出口的步数;代码:View Code #include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <queue>using namespace std;int xx[6] = 阅读全文
posted @ 2012-02-29 22:04 LT-blogs 阅读(253) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1573简单的搜索题就不说了;因为"whether or not the number before it is 1"wrong了两次;啊!!代码:View Code #include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;bool ok = 0;void print1(int n){ printf("%d step(s) to exi 阅读全文
posted @ 2012-02-26 22:14 LT-blogs 阅读(142) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/web/problem.php?action=showproblem&problemid=2389题意:判断表达式是否成立;精度要求非常高;代码:View Code #include <cstdio>#include <iostream>#include <cstring>#include <cstdlib>#include <algorithm>using namespace std;struct node{ char str[25]; double data;}link[55] 阅读全文
posted @ 2012-02-26 20:52 LT-blogs 阅读(186) 评论(0) 推荐(0) 编辑