上一页 1 ··· 3 4 5 6 7 8 下一页
摘要: 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) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2024这是大一的时候做的,今天做了一次忽然wa气死我 ,不过仔细看看还是一定小问题的,原因是因为没有%*c去除了字符垃圾的符号。。。。不过最好还是a了,合法的标识符,是字母或下划线开头,后面的只由数字,字母,下划线组成。。#include <stdio.h>#include <string.h>#include <stdlib.h>int main(){ int n,i; char a[60]; scanf("%d%*c",&n); while( 阅读全文
posted @ 2011-08-02 22:33 ○o尐懶錨o 阅读(767) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2030今天做了以前没有做过的这道题目,其实很简单就是汉字的机内码是由两个负的值组成,所以我们只要遍历过去,看a[i]负数的个数,再除以2即得到了该字符串内汉字的个数。。。代码如下:#include <stdio.h>#include <string.h>#include <stdlib.h>int main(){ int n; char a[1002]; scanf("%d%*c",&n); while(n--) { gets(a); int k 阅读全文
posted @ 2011-08-02 22:31 ○o尐懶錨o 阅读(427) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2035这道题目考察的是余数,因为((a%c)*(b%c))%b=(a*b)%c;所以这道题目就很简单了哦,相信你做了之后也会这样认为的。。。代码::#include <stdio.h>#include <string.h>#include <stdlib.h>int main(){ int n,m,k; while(scanf("%d%d",&n,&m),n&&m) { k=1; while(m--) { k=k*(n%1 阅读全文
posted @ 2011-08-02 22:30 ○o尐懶錨o 阅读(360) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1241今天第一次做DFS的题,虽然这道题目也可以用BFS,不过我还是觉得DFS简单,所以就用DFS,把八个方向的点都置为0,只剩一个2,所以只要查找2的个数即可。。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>int hash[120][120];void DFS(int x,int y){ if(x<0||y<0||(hash[x][y]!=2)) return ; if(hash[x][ 阅读全文
posted @ 2011-08-02 22:29 ○o尐懶錨o 阅读(140) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2042这道题目果断打表,打表之后一a,感觉以前自己觉得难,不想弄的东西,现在做起来,感觉以前自己的水平太菜了。。。代码:#include <stdio.h>#include <string.h>#include <stdlib.h>int a[40];int main(){ a[0]=3; for(int i=0;i<30;++i) { a[i+1]=(a[i]-1)*2; } int t,n; scanf("%d",&t); while( 阅读全文
posted @ 2011-08-02 22:21 ○o尐懶錨o 阅读(265) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2070这是一道很明显的水题,菲波拉契数,题目其实已经很明显了,只要找个数组模拟一下,打表就过了代码#include <stdio.h>#include <string.h>#include <stdlib.h>int main(){ __int64 a[51]; int n; a[0]=0;a[1]=1; for(int i=2;i<=50;++i) a[i]=a[i-1]+a[i-2]; while(scanf("%d",&n),n!=- 阅读全文
posted @ 2011-08-02 22:20 ○o尐懶錨o 阅读(395) 评论(0) 推荐(1) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2084这是一道很简单的DP题 ,我觉得就是一种思想,从后面往前面每次找和最大的,把每个数更新,一直往上推就可以了。。。我用了两种方法,一种的递归,一种递推递推代码:#include <stdio.h>#include <string.h>#include <stdlib.h>int a[100][100];void dp(int n){ for(int i=n-1;i>=0;--i) { for(int j=i;j>0;--j) { if(a[i][j]+a[i 阅读全文
posted @ 2011-08-02 22:15 ○o尐懶錨o 阅读(712) 评论(0) 推荐(1) 编辑
上一页 1 ··· 3 4 5 6 7 8 下一页