2012年7月20日
摘要: 第一个记忆化搜索,理解得差不多啦。贴下代码咯~CODE:1#include<stdio.h>2#include<stdlib.h>3#include<string.h>4usingnamespacestd;56intFIB[1001];78intfib(intn)9{10inti;11if(n>2)returnFIB[n]==-1?FIB[n]=fib(n-1)+fib(n-2):FIB[n];12elsereturn1;1314}151617intmain()18{19intn;20memset(FIB,-1,sizeof(FIB));21FIB[0 阅读全文
posted @ 2012-07-20 22:01 有间博客 阅读(646) 评论(0) 推荐(0) 编辑
摘要: 开始以为好难,会无限循环。后来发现题目中有一定会得到1这句话,那么就轻易AC了。好开心呐!~CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=300001;__int64odd[maxn];inttot;voidprint(intn){tot=0;if(n==0){printf("Nonumbercanbeoutput!\n");return;}while(n!=1){if(n&1){odd[tot++] 阅读全文
posted @ 2012-07-20 21:35 有间博客 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 简单模拟。注意结构体的二级排序以及字符串的排序。由于排序函数中间的n与N混淆,贡献了many WA。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>usingnamespacestd;intscore[15];constintSIZE=1010;structstu{chars[21];intgrade;}a[SIZE];intcmp(constvoid*a,constvoid*b){stu*p1=(stu*)a;stu*p2=(stu*)b; 阅读全文
posted @ 2012-07-20 20:57 有间博客 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 第一次只直接枚举写的,效率比较低。由于知道网上一定有更好的方法,所以去参考了别人的代码。所以第二次是用hash写的。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=1001;inta[1001];intsearch(int*a,intn,intv){inttot=0;for(inti=0;i<n;i++){if(a[i]==v)tot++;}returntot;}intmain(){intn;while(~scanf(&qu 阅读全文
posted @ 2012-07-20 17:11 有间博客 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 简单字符串排序问题。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>usingnamespacestd;constintSIZE=101;structindex{charstr[16];intbeg,end;}a[SIZE];intcmp1(constvoid*a,constvoid*b){index*p1=(index*)a;index*p2=(index*)b;returnp1->beg>p2->beg?1:-1;}in 阅读全文
posted @ 2012-07-20 16:46 有间博客 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 基础DP。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=10001;inta[maxn];intbeg,end;//开始,结束intget_max(int*a,intn)//算法复杂度为O(n){inti,j;beg=end=0;intMaxSum=0,ThisSum=0,index=0;intcnt=0,pos=0;for(i=0;i<n;i++){ThisSum+=a[i];if(a[i]<0)cnt++;//记 阅读全文
posted @ 2012-07-20 13:52 有间博客 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 简单模拟题。代码有点乱,感觉自己实现起来也有点麻烦。要加大力度练习啦!~CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>usingnamespacestd;constintmaxn=101;charstr[11][20]={"zero","one","two","three","four","five","six","seven",& 阅读全文
posted @ 2012-07-20 12:36 有间博客 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 简单模拟题。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>usingnamespacestd;constintmaxn=101;chars[maxn];inta[maxn];intget(char*s,int*a){intl=strlen(s);inttot=0,i=0,num=0;while(i<l){for(;i<l&&isdigit(s[i]);i++){num=num*10+s[i]-'0'; 阅读全文
posted @ 2012-07-20 10:00 有间博客 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 简单模拟题,主要是库函数的使用。fets(s, maxn, stdin);它使用时是一行一行的读入,且读取最大的字符数为maxn-1;最后补'\0',一旦遇到回车符'\n‘读取工作就会停止。这'\n'是该数组最后一个有效字符,再往后就是'\0'了。CODE:#include<stdio.h>#include<stdlib.h>#include<ctype.h>#include<string.h>usingnamespacestd;constintmaxn=1001;chars[maxn];i 阅读全文
posted @ 2012-07-20 09:19 有间博客 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 简单模拟题。求中位数CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>usingnamespacestd;constintmaxn=10001;inta[maxn];intcmp(inta,intb){returna<b;}intmain(){intn;while(~scanf("%d",&n)){inti;for(i=0;i<n;i++)scanf("%d",&a[i]);s 阅读全文
posted @ 2012-07-20 09:03 有间博客 阅读(116) 评论(0) 推荐(0) 编辑