摘要: http://poj.org/problem?id=2632题意:判断机器人在行走的过程中的状况;思路:简单的模拟题,就是有点麻烦;代码:View Code #include <cstdio>#include <iostream>#include <algorithm>#include <cstdlib>#include <cstring>using namespace std;struct node{ int x; int y; int ford;}link[110];int x = 0;int y = 0;int visit[11 阅读全文
posted @ 2012-02-26 11:04 LT-blogs 阅读(160) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3295题意:判断一个表达式的值是否都为1,p, q, r, s, and t 为取值为true或false的元素,K, A, N, C, E则为对应的运算法则;思路:从后往前递推,并且要尝试所有的取值可能;代码:View Code #include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cstdlib>#include <stack>using namespa 阅读全文
posted @ 2012-02-25 19:23 LT-blogs 阅读(180) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1328题意:在一个海岸线上按一些雷达,是雷达可以覆盖海面的小岛,问最少安装多少雷达;思路:快拍+贪心;代码:View Code #include <stdio.h>#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <string.h>#include <cmath>using namespace std;struct node{ double 阅读全文
posted @ 2012-02-25 09:06 LT-blogs 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 题意和2965差不多,思路也是一样的:链接:2965代码:View Code #include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;int s[16] ={ 0xc800,0xe400,0x7200,0x3100, 0x8c80,0x4e40,0x2720,0x1310, 0x08c8,0x04c4,0x0272,0x0131, 0x008c,0x004e,0x0027,0x0013};int result = 1 阅读全文
posted @ 2012-02-23 20:30 LT-blogs 阅读(150) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2965 位运算+搜索题意:将下图这样的图案都变成减号,规则每次改变一个,这一个的行和列都会发生转换;思路:总共有2^16的情况,全部都搜一遍,用位运算一次改变一行和一列;-+-----------+--搜索题解:View Code #include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;int result = 17;int path = 0;int s[16] 阅读全文
posted @ 2012-02-23 20:00 LT-blogs 阅读(138) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2196题意:在一个每条边都有权值的树中,求每个顶点能走的最大距离;思路:两次dfs,以1为根结点,一次从叶子到根结点,求出最远距离和次远距离。另一次从根进行dfs.(res[]为经过父节点能走最长距离)代码:View Code #include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <vector>#define sum 10010using 阅读全文
posted @ 2012-02-21 21:56 LT-blogs 阅读(143) 评论(0) 推荐(0) 编辑
摘要: http://acm.timus.ru/problem.aspx?space=1&num=1353题意:输入一个s,求从1-10^9的数中各位数字之和是s的个数;思路:采用一个0-81的数组记录和为i的个数,然后对每一位都从0-9进行遍历;View Code #include<cstdio>using namespace std;int main(){ int ans[100],temp[100],n,i,j,k; for(i=0;i<100;i++) ans[i]=temp[i]=0; scanf("%d",&n); if(n==1) p 阅读全文
posted @ 2011-12-10 09:50 LT-blogs 阅读(273) 评论(0) 推荐(0) 编辑
摘要: http://acm.timus.ru/problem.aspx?space=1&num=1081无语了一个简单题花了一个下午才调出来,悲剧啊;题意:给定一个有N个元素的字符串,每个元素都是0或1,且1和1不能相连,问第n个字符串是什么;思路;首先是一个斐波那契数列,然后往下减输出;View Code #include<cstdio>#include<cstring>using namespace std;int s[50];void pp(int i,int num){ if(i<1) return ; if(i<=1) { if(num==1|| 阅读全文
posted @ 2011-12-08 18:46 LT-blogs 阅读(169) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1742背包真的很神奇啊;题意:给你一些硬币,每种硬币有一定的价值和数目,用这些硬币能组合成多少小于s的组合;思路:采用背包,在这里要加一个记录个数的数组num[],这样就变成二维的了,减少了时间;View Code #include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int main(){ int n,s,ans[100010],num[100010],val[110 阅读全文
posted @ 2011-12-07 20:55 LT-blogs 阅读(204) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/web/problem.php?action=showproblem&problemid=1566这是上个星期测试赛的最后一个题目,那天真是悲剧了,一个也没做出来,;思路:采用VONGONG的思路做的,用bfs搜索来找:View Code #include<cstdio>#include<iostream>#include<algorithm>#include<string.h>using namespace std;int map[55][55];int p(int w){ int temp 阅读全文
posted @ 2011-12-07 19:31 LT-blogs 阅读(304) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2639题意:给你一些Bone和一个背包体积,求第K大的价值;思路:采用了三维的数组第三维是存(1-k)大的值的:View Code #include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;int val[120],vv[120];int ans[1200][120],a[120],b[120];int main(){ int q,n,v,k 阅读全文
posted @ 2011-12-06 20:17 LT-blogs 阅读(207) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2264题意:找出一个包含两个字串的最短的串;思路:先找出两个字符串的LCS,然后构造目标字符串。例如,有两个字符串 apple pffeach 这两个字符串的LCS是P E 那么分别找出P,E在两个字符串的位置,再将不属于LCS的字符插进来,就变成了: (a) P (pl) (ff) E (ach)View Code #include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){ char a[105] 阅读全文
posted @ 2011-12-02 21:01 LT-blogs 阅读(311) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1159题意:给一个长度为n的串,求将其变成回文要增加的最少字符数.思路:LCS算法:状态方程:if(a[i]==b[j]) ans[i][j]=max1(ans[i-1][j-1]+1,ans[i-1][j],ans[i][j-1]); else ans[i][j]=max(ans[i-1][j],ans[i][j-1]);二维数组的形式(必须用short,否则超内存):View Code #include<cstdio>#include<algorithm>#include<cstring>using 阅读全文
posted @ 2011-12-02 18:48 LT-blogs 阅读(155) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1836题意:从一列士兵中剔除一些,使剩下的符合a1>a2>a3>...>ai ai+1<ai+2<....<aN-1<aN思路:用了两个LIS分别从前往后和从后往前,得到啊a[],b[],最后取a[i]+b[i]的最大值;View Code #include<cstdio>#include<cstring>#include<algorithm>using namespace std;double s[1010];int n,a[1010],b[1010],i 阅读全文
posted @ 2011-11-29 18:58 LT-blogs 阅读(151) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1025题意:题目的意思就是有两种城市,穷和富,要富的运到穷的里面问你最多能建几条路。思路:就是按穷的递增序列来找富的城市里的最大上升子序列。就是LIS法,因为有500000个数据所以用普通的方法肯定超时,那么就用二分查找就可以了。每次就是找第一个比这个数大的数如果没有就放在最右边把最长的序列加一,否则把第一个比他大的数给替换掉。View Code #include<cstdio>using namespace std;int n;int s[500010],ans[500010],a,b;int 阅读全文
posted @ 2011-11-29 14:05 LT-blogs 阅读(184) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2082又是一个母函数模板题,不多说了:View Code #include<cstdio>using namespace std;int main(){ int n,s[27],c1[100],c2[100],sum,i,j,k,w; scanf("%d",&n); while(n--) { for(i=1;i<=26;i++) scanf("%d",&s[i]); for(i=0;i<=50;i++) c1[i]=c2[i]=0 阅读全文
posted @ 2011-11-27 10:31 LT-blogs 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 一个母函数的题目,基本上还是模板题,还是不太熟悉啊;http://acm.hdu.edu.cn/showproblem.php?pid=1709View Code #include<cstdio>using namespace std;int s[110],c1[10010],c2[10010];int main(){ int n,sum,i,j,k; while(scanf("%d",&n)!=EOF) { sum=0; for(i=1;i<=n;i++) { scanf("%d",&s[i]); sum... 阅读全文
posted @ 2011-11-26 20:15 LT-blogs 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 两道母函数的模板题:http://acm.hdu.edu.cn/showproblem.php?pid=1398View Code #include<iostream>#include<cstdio>using namespace std;int c1[310],c2[310];int main(){ int n,i,j,k; while(scanf("%d",&n),n) { for(i=0;i<=n;i++) { c1[i]=1; c2[i]=0; } for(i=2;i*... 阅读全文
posted @ 2011-11-26 18:09 LT-blogs 阅读(180) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1171一道水题,用来熟悉一下母函数;多重背包:View Code #include<iostream>#include<cstdio>using namespace std;int value[55],num[55],ans[250010];int main(){ int n,sum,w,i,j,k; while(scanf("%d",&n),n>0) { sum=0; for(i=1;i<=n;i++) { scanf("%d%d&q 阅读全文
posted @ 2011-11-26 16:46 LT-blogs 阅读(141) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3449这个题AC的有点稀里糊涂(是1A过的),采用的01背包的方法;思路:定义了两个数组用来存储最终结果和但购买这一组的篮子是的价值,然后a[j]=max(a[j],b[j-link[i].pi]);把最终结果给a[],每次找完一组的时候更新一下;View Code 1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 #include<cstdlib> 5 #include<cs 阅读全文
posted @ 2011-11-25 21:57 LT-blogs 阅读(287) 评论(0) 推荐(0) 编辑