随笔分类 -  活动活动

摘要:1: /// 2: /// Assume you have a method isSubstring which checks if one word is a substring of another. 3: /// Given two strings, s1 and s2, 4: /// write cod... 阅读全文
posted @ 2014-01-10 12:49 Dance With Automation 阅读(197) 评论(0) 推荐(0)
摘要:1: /// 2: /// Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0. 3: /// 4: class Program 5: { ... 阅读全文
posted @ 2014-01-07 19:21 Dance With Automation 阅读(251) 评论(0) 推荐(0)
摘要:1: /// 2: /// Q:Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, 3: /// write a method to rotate the image by 90 degrees. Can yo... 阅读全文
posted @ 2014-01-07 18:51 Dance With Automation 阅读(297) 评论(0) 推荐(0)
摘要:1: class Program 2: { 3: static void Main(string[] args) 4: { 5: string s = File.ReadAllText(@"e:\test.txt"); 6: Program p =... 阅读全文
posted @ 2013-12-30 20:31 Dance With Automation 阅读(292) 评论(0) 推荐(0)
摘要:1: class Program 2: { 3: static void Main(string[] args) 4: { 5: string s = File.ReadAllText(@"e:\test.txt"); 6: Program... 阅读全文
posted @ 2013-12-27 20:04 Dance With Automation 阅读(386) 评论(0) 推荐(0)
摘要:1: class Program 2: { 3: static void Main(string[] args) 4: { 5: string s = File.ReadAllText(@"e:\test.txt"); 6: Prog... 阅读全文
posted @ 2013-12-27 11:04 Dance With Automation 阅读(263) 评论(0) 推荐(0)
摘要:1: class Program 2: { 3: static void Main(string[] args) 4: { 5: Program p = new Program(); 6: string r = p.ReverseString("5毛1234\0"); 7: ... 阅读全文
posted @ 2013-12-25 20:27 Dance With Automation 阅读(299) 评论(0) 推荐(0)
摘要:1: class Program 2: { 3: static void Main(string[] args) 4: { 5: Program p = new Program(); 6: List result = p.FindMostF... 阅读全文
posted @ 2013-12-24 20:34 Dance With Automation 阅读(252) 评论(0) 推荐(0)
摘要:自己用单链表实现如下: 1: #include <stdio.h> 2: #include <stdlib.h> 3: #include <math.h> 4: 5: /*Radix Sort*/ 6: #define MAX_COUNT 100 7: #define BASE 10 8: typedef struct node snode; ... 阅读全文
posted @ 2012-07-25 11:26 Dance With Automation 阅读(327) 评论(0) 推荐(0)
摘要:在之前的文章里偶分析了追赶法判断链表是否有环(叫龟兔赛跑法可能会更贴切)算法的正确性。但是还有几个问题必须解决:1. 环的长度2. 环的入口 3.整个链表的长度第一个问题很好解决,因为龟兔二人第一次相遇的点(不放设为k)必然在环内,这时再以相遇点作为起点,新定义一向量向前移动,直到移动到自身为止,移动的步数就是环的长度,这个很好理解。第二个问题稍微要思考一下,如果使用标记法,这个问题很好解决,但是... 阅读全文
posted @ 2012-07-07 10:54 Dance With Automation 阅读(471) 评论(0) 推荐(0)
摘要:C专家编程在附录A2讨论了链表环检测的算法,实现一下,算法一通过设置标志,复杂度O(N),算法二就是所谓的追赶法,算法还是很好理解的,在链表尾部形成的环中,假设两个步伐不一致的的人在绕圈,总有一个交点,但是要证明该算法的正确性似乎还要费一些精力。先给出实现: 1: /* 2: Expert C Programming,Chinese Edition 3: How to detect loop in linked list, p274,solution1 4: */ 5: int check_loop1(pnode list) 6: { 7: p... 阅读全文
posted @ 2012-07-05 22:54 Dance With Automation 阅读(668) 评论(0) 推荐(0)
摘要:given a list as: Header->1->2->3->4->5 reverse it, the idea should be like: Step1:Header->2->1->3->4->5 Step2:Header->3->2->1->4->5 Step3:Header->4->3->2->1->5 Step4:Header->5->4->3->2->1 running tim... 阅读全文
posted @ 2012-07-02 22:23 Dance With Automation 阅读(283) 评论(0) 推荐(0)
摘要:Here I give two insertion sort, one use array, another use list. I also get a conclusion that nothing better in insertion_sort2 than insertion_sort, maybe the size is too large and too random which wi... 阅读全文
posted @ 2012-06-29 09:06 Dance With Automation 阅读(174) 评论(0) 推荐(0)
摘要:1: #include <stdio.h> 2: #include <stdlib.h> 3: #define MAX_LENGTH 9999 4: void print_array(const int a[],int size) 5: { 6: int i=0; 7: for(i=0;i<size;i++) 8: { 9: printf("%d,",a[i]); 10: } 11: printf("\n"); 12: } 13: 14: /* 15: as... 阅读全文
posted @ 2012-06-29 09:02 Dance With Automation 阅读(1708) 评论(0) 推荐(0)
摘要:最近在看最大公约数的一些性质,很有意思,有些性质simple,beautiful,乍看上很明显,但依旧需要思索一番才敢确认嘛。 如wikiepdia给出的这条性质: 现证明第二行: 不妨假设最大公约数为d,则a,b可以写成a=dx,b=dy的形式(乘积!非微分哦)。 于是a-b=d(x-y),于是命题证明变成要证明a-b=d(x-y)和b的最大公约数即是a与b的最大公约数。 而a-b=d(x-y... 阅读全文
posted @ 2012-06-23 19:02 Dance With Automation 阅读(3363) 评论(3) 推荐(2)
摘要:首先给出wikipedia上Stein算法的理论依据: The algorithm reduces the problem of finding the GCD by repeatedly applying these identities: gcd(0, v) = v, because everything divides zero, and v is the largest number ... 阅读全文
posted @ 2012-06-23 19:00 Dance With Automation 阅读(369) 评论(1) 推荐(0)
摘要:簊亍书丄旳峛孒,①個潲嶶攺進了①些旳冪運匴,加了一个简单的check,以及改成了位运算。 1: #include <stdio.h> 2: #include <stdlib.h> 3: #include <limits.h> 4: 5: unsigned long power(int base,int n) 6: { 7: //a simple... 阅读全文
posted @ 2012-06-23 18:59 Dance With Automation 阅读(144) 评论(0) 推荐(0)
摘要:use poly ADT: 1: #include <stdio.h> 2: #include <stdlib.h> 3: #define MAX_DEGREE 9999 4: 5: struct polynomial 6: { 7: int coeff_array[MAX_DEGREE]; 8: int maxpower; ... 阅读全文
posted @ 2012-06-23 18:59 Dance With Automation 阅读(307) 评论(0) 推荐(0)
摘要:use simple linked list ADT: about the running time of polynode multiply2(const polynode p1,const polynode p2), assume size of p1 is M,size of p2 is N, the result should be: M*N+2N+3N+4N+5N+…+(M-1)N=M*... 阅读全文
posted @ 2012-06-23 18:58 Dance With Automation 阅读(362) 评论(0) 推荐(0)
摘要:依旧现贴出程序代码再进行分析: 1: #include <stdio.h> 2: #include <stdlib.h> 3: 4: int sc=0; 5: int max3(int a,int b, int c) 6: { 7: sc++; 8: if(a>b) 9: { 10: return... 阅读全文
posted @ 2012-06-17 13:33 Dance With Automation 阅读(222) 评论(0) 推荐(0)