摘要: 最长公共子序列:用一个二维数组进行处,注意处理初始边界的问题;#include<iostream>#include<string>const int Max=1000;int res[Max][Max];using namespace std;int main(){ string str1,str2; int len1,len2; while(cin>>str1>>str2) { int i,j; memset(res,0,sizeof(res)); len1=str1.length(); len2=str... 阅读全文
posted @ 2012-03-26 17:18 orangeblog 阅读(196) 评论(0) 推荐(0) 编辑
摘要: bfs() 阅读全文
posted @ 2012-03-24 18:07 orangeblog 阅读(1118) 评论(0) 推荐(0) 编辑
摘要: 自己用暴力做的,超了,网上搜了之后才知道还带这样滴;#include<iostream>#include <string>//#include <window.h>//#include <system>using namespace std;const int Max=1000011;int next[Max];//int flag[Max];string str;void get_next(int n){ int j=-1; int i=0; while(i<n) { if(j==-1||str[i]==str[j]) { j++;i+. 阅读全文
posted @ 2012-03-24 10:38 orangeblog 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 字符串匹配中的一种KMP,该算法的关键是求出next[],当然理解是必须的,期待更深入的了解;hdu2087代码:#include<iostream>#include<string>using namespace std;const int Max=1001;string str,tar;int next[Max];//next串有很多变通的用法,例如hdu1358就是利用next来求重复前缀;///////////////////////////////////////////////////////////////////////////////////////// 阅读全文
posted @ 2012-03-23 17:00 orangeblog 阅读(191) 评论(0) 推荐(0) 编辑
摘要: acer 生涯的第一道Bfs,终于ac了。刚开始与深搜弄混了,自己也晕了一上午。()还有就是queue中几个函数的用法;pop()//删除队首元素front()获得队首元素push()//back(),empty()// 1 #include <iostream> 2 #include <queue>//注意与<queue.h>的区别 3 using namespace std; 4 const int Max=100001; 5 queue <int>q; 6 int used[Max]; 7 int step[Max]; 8 int totl 阅读全文
posted @ 2012-03-23 14:53 orangeblog 阅读(694) 评论(0) 推荐(0) 编辑
摘要: 题目大意:http://acm.hdu.edu.cn/showproblem.php?pid=2181; 深度搜索! 搜索有很多种,有简单的for循环(不一定简单),而深度搜索或是广度搜索其实考察的是对递归的理解程度; 这里先说说个人对深搜的理解; 注意以下几点: 1.Dfs()应该什么类型,void 还是其他的什么类型;2.Dfs() 中有哪些参数3.还有就是对标记数组(就是用于标志某个结点是否被访问过的数组) 4.....................#include <iostream>using namespace std;int map[21][3];//用于记录i城市 阅读全文
posted @ 2012-03-22 22:02 orangeblog 阅读(420) 评论(0) 推荐(0) 编辑
摘要: 有点进步了,accepted 二分图 1.最大匹配 2.最小点覆盖(来源于最大匹配) hdu1054就是关于最小点覆盖的问题(貌似还能用树状DP,贪心算法来做,待完成),明白了最大匹配与最小点覆盖的关系这题也就easy 了//静以修身//答应自己的就不要失信#include <iostream>#include <vector>//如果换成<vector.h>就编译错误,但在codeblocks上可以通过using namespace std;const int Max=100000;int link[Max],used[Max];vector <in 阅读全文
posted @ 2011-11-21 22:31 orangeblog 阅读(672) 评论(0) 推荐(0) 编辑
摘要: 并查集者,并也,查也,统统归于集合也。即其是关于集合的操作——并,查。所以并查集的关键也就是对集合的合并与对元素的查找,查找某一元素属于哪个集合。一般情况下定义一个数组flag[](数组真是太有用了),用来记录每个元素所属的集合。当然如果用一般情况去查或是合并元素,find()与merge()两个函数的复杂度为n。看起来时间复杂度并不大,但这里我们还可以进行改进,就是利用树结构。如果flag[i]= i//i就是这个树的跟 如果flag[i]=j且i<>j j就是i的父节点 根据这个思想完成find()与merge()函数int find(int x){ int r; r=x; . 阅读全文
posted @ 2011-11-08 09:03 orangeblog 阅读(1205) 评论(1) 推荐(0) 编辑
摘要: 没思路,看了网上各路好汉的分析之后略懂一二。 任一个数m可以表示成10^(n+x),这里n为整数,x是小数。我们知道10^(n+x)=(10^n)*(10^x),前者的结果很明显,所以只要求出10^x,就可以知道m最左面的数值。 (够shit)#include <iostream>#include <math.h>using namespace std;int main(){ double x,m,sum; __int64 i,res,b; __int64 n; cin>>n; //如果换成scanf("%I64d",&n);会超 阅读全文
posted @ 2011-11-02 15:31 orangeblog 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 大数除,有了心得hdu2117是让求小数点某一位小数,仔细分析相当于大数除以一个小数(因为要求的某一位的位置可能非常靠后)代码可以向下面:#include <iostream>using namespace std;int main(){ int n,m,f,x,i; while(cin>>n>>m) { f=10; if(n==1) {cout<<0<<endl;continue;} for(i=0;i<m;i++) { x=f/n; //关理三 f=f... 阅读全文
posted @ 2011-10-30 14:09 orangeblog 阅读(245) 评论(0) 推荐(0) 编辑