2011年3月21日

摘要: 【1】给一系列数:a1,a2,a3,...,an,要求找出其中2个数ai,aj,使得ai+aj=X,算法时间复杂度为:O(nlogn)。思路:先排序,采用快排。在设置2个指针low、high,分别指向第一个、最后一个数,然后向中间扫描靠拢,遇到a[low]+a[high]就输出。直到low=high。参考代码:#include<stdio.h>#define MAXLEN 1000int partition(int a[],int low,int high){ int pivotkey=a[low]; while(low<high){ while(low<high&am 阅读全文
posted @ 2011-03-21 15:28 江南烟雨hust 阅读(292) 评论(0) 推荐(0)
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=2203AC代码:#include<stdio.h>#include<string.h>#define MAXLEN 100005char s1[MAXLEN],s2[MAXLEN];int IsSubset(int len1,int len2){ int i,j,k; for(i=0;i<len1;i++){ if(s1[i]==s2[0]){//遇到字符与s2首字符相等; j=i+1; k=1; while(k<len2&&s1[j]==s2[k]& 阅读全文
posted @ 2011-03-21 14:23 江南烟雨hust 阅读(205) 评论(0) 推荐(0)

2011年3月20日

摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=2206这道题要考虑的地方很多:1、是否含有除0-9、.之外的字符;2、.的个数是否是3个;3、4部分的数值是否都在0-255之间;4、是否有连续的.;考虑到这几个方面,基本上就能AC了。我测试了好多数据,终于AC了~~~我的AC代码:#include<stdio.h>#include<string.h>int IllegleChar(char c){ if((c>='0'&&c<='9')||c=='.' 阅读全文
posted @ 2011-03-20 21:04 江南烟雨hust 阅读(207) 评论(0) 推荐(0)
摘要: 题目啊:http://acm.hdu.edu.cn/showproblem.php?pid=1727我的方法很笨,不知道有没有什么好方法~~~这道题说实话,也不是很水,要考虑的方面其实很多的,我调了好半天,终于由WA变为AC,不容易啊~~~AC代码:#include<stdio.h>char s[10][10]={"zero","one","two","three","four","five","six","seven",& 阅读全文
posted @ 2011-03-20 20:01 江南烟雨hust 阅读(171) 评论(0) 推荐(0)
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1200AC代码:#include<stdio.h>#include<string.h>int main(){ int c,len,i,j,k,row,count,flag; char s1[201],p[21][201],s2[201]; while(scanf("%d",&c)!=EOF){ //c表示列数; getchar();//接受回车符; if(c==0){ break; } gets(s1); len=strlen(s1); i=0; ro 阅读全文
posted @ 2011-03-20 15:10 江南烟雨hust 阅读(198) 评论(0) 推荐(0)

2011年3月18日

摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=2115题目有一句话:“Output a blank line between two cases.“。开头提交Presentation Error,很是上火!!!总是忽略这个地方,调了半天~~~终于AC~~~AC代码:#include<stdio.h>#include<string.h>#include<stdlib.h>//包含qsort函数的头文件;struct node{//运动员结构体定义; char name[20],time[6]; int t;//时间( 阅读全文
posted @ 2011-03-18 18:46 江南烟雨hust 阅读(147) 评论(0) 推荐(0)
摘要: 【1】输入一个十进制数,将其先转化为八进制数,然后再输出。参考代码:#include<stdio.h> #include<stdlib.h>int main() { int a = 0 ; printf ("Please enter a decimal number:") ; scanf ("%d",&a) ; printf ("%d's octal number is %o/n",a,a) ; //system("pause");} 数据测试:【2】用户输入一个文本名,编程 阅读全文
posted @ 2011-03-18 18:38 江南烟雨hust 阅读(183) 评论(0) 推荐(0)

2011年3月17日

摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1159问题的递归式写成:代码:#include<stdio.h>#include<string.h>#define MAXLEN 505void LCSLength(char *x,char *y,int m,int n,int c[][MAXLEN]){//求最长公共子序列; int i,j; for(i=0;i<=m;i++){ c[i][0]=0; } for(i=0;i<=n;i++){ c[0][i]=0; } for(i=1;i<=m;i++){ f 阅读全文
posted @ 2011-03-17 14:53 江南烟雨hust 阅读(220) 评论(0) 推荐(0)

2011年3月16日

摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1702定义字符串数组的时候原来是这样写的:char s[4],p[3];结果总是不对,调了半天啊。。。看来开数组的时候只要不影响空间可以适当开大一点。。。。。AC代码:#include<stdio.h>#include<string.h>#define maxsize 1000int main(){ int n,m,temp,stack[maxsize],top,front,rear; //用数组模拟队列、栈; char s[5],p[4];//记录进出栈方式; scanf(&q 阅读全文
posted @ 2011-03-16 21:20 江南烟雨hust 阅读(372) 评论(0) 推荐(0)

2011年3月14日

摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=3792总是超时,搞了半天才搞好,抑郁。。。。。。。。。。。。。。。。。。。。。。代码:[服务器生成] 通行证:KSDA291730794 密码:21024731 #include<stdio.h> #include<math.h> #define N 100000 int main(){ int n,i,j,temp,a[N],b[N]; a[0]=a[1]=0; for(i=2;i<N;i++){ a[i]=1;//数组初始化; } temp=(int)sqrt(N); 阅读全文
posted @ 2011-03-14 20:59 江南烟雨hust 阅读(202) 评论(0) 推荐(0)

导航