摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2069这道题一看就是母函数,于是就觉得它很简单,出现了错误的代码:#include<stdio.h>int main(){ int n; int i,j,k; int a[1000],b[1000],num[6]={0,1,5,10,25,50}; while(scanf("%d",&n)!=EOF) { for(i=0;i<=n;i++) { a[i]=1; b[i]=0; } for(i=2;i<=5;i++) { for(j=0;j<=n;j++ 阅读全文
posted @ 2011-08-03 22:04 ○o尐懶錨o 阅读(67) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1358几天看了kmp,觉得其实挺有趣的,可是当自己做题的时候才知道,它的用法是很灵活的,当计算重复子串的时候最好next的下标为-1开始,并且要注意数组的大小,因为数组开小了,所以一直wa。。。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>char s[1000000];int len,next[1000000];int main(){ int t=0,a; while(scanf("%d&q 阅读全文
posted @ 2011-08-03 16:29 ○o尐懶錨o 阅读(246) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1711做了KMP,感觉有点不懂为什么要next函数,最后问了涛神,懂了,原来next是找出自己重复的子串,只要有重复的就直接移动过去就可以了,第一次做KMP一a,这是赤裸裸的模版的,水题#include <stdio.h>#include <string.h>#include <stdlib.h>int n,m;int a[1000002],b[1000002],next[1000002];void getnext(){ int i=1,j=0; next[1]=0; wh 阅读全文
posted @ 2011-08-03 16:26 ○o尐懶錨o 阅读(183) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3336hdu 3336 Count the string 【经典 KMP】+【DP】【题意】给你一个字符串,然后让你把所有的前缀给找出来,并把它们在字符串中的出现次数相加,输出这个和【分析】找出前缀后,算出现次数,很明显的是一个单模式串匹配问题,KMP 可以很好的解决,不过如果直接这样暴力的话,O(n^2) 的复杂度还是不行的。。。因此,我们试着考虑 KMP 算法进行快速匹配的本质核心所在,其实就是 next[] 数组而这个的本质其实就是 S[1..next[i]]=S[i-next[i]+1...i]即模式 阅读全文
posted @ 2011-08-03 16:22 ○o尐懶錨o 阅读(1165) 评论(0) 推荐(2) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2031今天下午翻到11页突然发现我的水题系列还有好多没有做,呵呵,一试手感还不错,只是一个小小的错误,wa。。。。本题就是利用assic码值,用字符串读出更方便吧,不过一改就对了,感觉真不错。。。#include <stdio.h>#include <string.h>#include <stdlib.h>int main(){ int m,n,r,a[1000],k,flag; while(scanf("%d%d",&n,&m)!=EO 阅读全文
posted @ 2011-08-03 16:15 ○o尐懶錨o 阅读(661) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1686KMP算法,今天又到了好晚,不过今天总的来说收获还是很大的,做了好几道KMP的题目,呵呵,心情也还不错,这是一道纯模版题,感觉很简单,就是去b中找a的个数,当j=m的时候说明一个字符串匹配成功,然后求输出个数即可。。。#include <stdio.h>#include <string.h>#include <stdlib.h>int next[1000000],m,n;char a[1000000],b[1000000];void getnext(){ int i= 阅读全文
posted @ 2011-08-03 16:08 ○o尐懶錨o 阅读(267) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2028深夜十二点水的题,第一次wa,不过后来看看很简单,gcd求最大公约数,然后每次求出最小公倍数。。。最后知道用该数除以最大公约数再乘以本身就可以了#include <stdio.h>#include <string.h>#include <stdlib.h>int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}int main(){ int n,a,b,k; while(scanf("%d",&n)! 阅读全文
posted @ 2011-08-03 15:59 ○o尐懶錨o 阅读(1318) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2029这是一道回文串,以前我老是用for循环,不过今天试了试while觉得还挺好用的,呵呵,果断、一a了 。。好开心啊 ,今天有个好的开始不错哦!回文就是前面和后面一直匹配。。。若有不同的就跳出并且输出no,若一直到最后都没有不同就输出yes#include <stdio.h>#include <string.h>#include <stdlib.h>int main(){ int n,m; char a[10002]; scanf("%d",& 阅读全文
posted @ 2011-08-03 15:54 ○o尐懶錨o 阅读(296) 评论(0) 推荐(1) 编辑