coder_new

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  data Structure and algorithm

摘要:[Input example]2710 30 30 10 20 0 30 30 50 10 40 50 60 30208 -2 39 38 -22 -5 0 64 70 -8 -7 -30 40 -21 68 12 30 46 58 45 -24 40 8 1 16 66 41 58 37 25 20 -22 43 38 -12 14 29 40 -9 -4[Output example]1500.006863.50#include #include typedef struct _SPOT_{ int x; int y;} Spot;int N;Spot data[105];in... 阅读全文
posted @ 2014-03-06 16:13 coder_new 阅读(300) 评论(0) 推荐(0)

摘要:[Input Example]2101 2 3 4 5 6 7 8 9 91027 22 15 30 29 12 20 13 6 10[Output Example]10 9 8 7 6 5 4 3 1 13 4 6 1 2 8 5 7 10 91.排序#include #include #include int N;typedef struct _SIS SIS;struct _SIS { int pos; int val;};SIS Sis[300005];int order[300005];int comp(const void *a, const void *b){ ... 阅读全文
posted @ 2014-03-04 10:26 coder_new 阅读(248) 评论(0) 推荐(0)

摘要:[Input Example]241 1 5 5 5 7 10 1015-15 41 50 47 10 54 71 -57 35 -64 27 -70 -88 77 48 83 8 90 69 -96 29 -3 89 -9 -50 19 6 26 66 32[Output Example]2 35 61.分治#include #include #include #define N 10000#define MAX 0x7FFFFFFFint num;typedef struct _STAR STAR;struct _STAR{ int x; int y; int index... 阅读全文
posted @ 2014-03-01 10:12 coder_new 阅读(898) 评论(0) 推荐(0)

摘要:单向链表typedef struct _LINKED_NODE LINKED_NODE;struct _LINKED_NODE { int data; LINKED_NODE *next;};链表节点建立LINKED_NODE *createLinkedNode(int nValue){ LINKED_NODE *pNode=NULL; pNode=(LINKED_NODE *)malloc(sizeof(LINKED_NODE)); if(pNode==NULL) return NULL; pNode->data=nValue; pNode->nex... 阅读全文
posted @ 2014-02-08 10:56 coder_new 阅读(281) 评论(0) 推荐(0)

摘要:#include #include #define MAX 10int comMatrix[MAX][MAX];char comstr[MAX];char *commonString(char string1[], char string2[]){ int len1=0,len2=0; int flag=0; int max=0; int i, j; while(string1[len1]!='\0') len1++; while(string2[len2]!='\0') len2++; for(i=0;i0&&j>0&&c 阅读全文
posted @ 2014-02-08 10:50 coder_new 阅读(196) 评论(0) 推荐(0)

摘要:冒泡排序:稳定,时间复杂度O(n2),空间复杂度O(1)//bubblevoid bubblesort(int *a, int n){ int hig=n-1; int i; while(hig) { for(i=0;ia[i+1]) swap(&a[i],&a[i+1]); } hig--; }}鸡尾酒排序:稳定,时间复杂度O(n2),空间复杂度O(1)。冒泡排序的变形。//cocktailvoid cocktailsort(int *a ,int n){ int low=0,hig=n-1; int i; ... 阅读全文
posted @ 2014-02-08 10:06 coder_new 阅读(204) 评论(0) 推荐(0)

摘要:#include #include #define N 5int getMaxSum(int a[N]){ int sumTemp=0, sum=a[0]; int i; for(i=0; i<N; i++) { if(sumTemp<0) sumTemp=a[i]; else sumTemp+=a[i]; if(sum<sumTemp) sum=sumTemp; } return sum;}int main(){ int a[]={-1,5,2,-2,8}; printf("%d\n", getMaxS... 阅读全文
posted @ 2014-02-08 09:57 coder_new 阅读(158) 评论(0) 推荐(0)

摘要:最大堆:排序以及最小k个数堆排序:不稳定,平均情况和最坏情况的时间复杂度O(nlogn),空间复杂度O(1)void swap(int *a, int *b){ int temp; temp=*a; *a=*b; *b=temp;}void heapDown(int *a, int n){ if(n=1;i--) { swap(&a[i],&a[0]); heapDown(a,i-1); }}void minK(int *a, int n, int k){ if(n<=0) return; if(k<=0) re... 阅读全文
posted @ 2013-12-27 15:58 coder_new 阅读(236) 评论(0) 推荐(0)