摘要: 转自http://hi.baidu.com/zhangwp999/blog/item/185f9afba454ba63024f5675.html*六类qsort排序方法P.S.:qsort函数是ANSI C标准中提供的,其声明在stdlib.h文件中,是根据二分发写的,其时间复杂度为n*log(n),其结构为:void qsort(void *base,size_t nelem,size_t width,int (*Comp)(const void *,const void *));其中:*base 为要排序的数组nelem 为要排序的数组的长度width 为数组元素的大小(一字结为单位)(* 阅读全文
posted @ 2012-07-11 23:01 _雨 阅读(339) 评论(0) 推荐(0) 编辑
摘要: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1415水题 简单排序查找 快排+哈希View Code 1 #include <stdio.h> 2 #include<string.h> 3 int cmp(const void*a,const void *b) 4 { 5 return *(int *)a-*(int *)b; 6 } 7 int main() 8 { 9 int i,j,n, m, a 阅读全文
posted @ 2012-07-11 22:20 _雨 阅读(188) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2488小错误不断 数组开的a[8][2] 我居然循环到8 还一直纠结哪错了改完后 交了一次WA 看了看讨论里面 要根据字典序 所以移动坐标差a[8][2]只能那么定义 具体看代码View Code 1 #include <stdio.h> 2 #include <string.h> 3 int n,m,x[27][27],q[27],flag; 4 char w[27]; 5 int u[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}}; 阅读全文
posted @ 2012-07-11 21:28 _雨 阅读(160) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1016这几天做题第一次一次性AC 自信心上涨简单dfs一个大圈 中有n个小圈 填进去数 相邻圈中数的和为素数View Code 1 #include <stdio.h> 2 #include<string.h> 3 int x[21][21],v,f,y[21],c[21],n; 4 int prime(int x) 5 { 6 int i,flag = 1; 7 for(i = 2; i < x ; i++) 8 if(x%i == 0) 9 {10 ... 阅读全文
posted @ 2012-07-11 19:45 _雨 阅读(224) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2258dfs 边是双向的 节点可以走多次 开个二维数组标记边 因为可以从任一节点出发所以n次dfsView Code 1 #include <stdio.h> 2 #include<string.h> 3 int x[26][26],v,w,n; 4 void dfs(int i,int v) 5 { 6 int j; 7 for(j = 0 ; j <= n-1 ; j++) 8 { 9 if(x[i][j] == 1)10 {11 x[i][j] = 0;... 阅读全文
posted @ 2012-07-11 19:03 _雨 阅读(258) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2139BFS 借助队列 将节点的邻接点依次存入队中View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<string.h> 4 int k[1001][1001],f[1001],n,m,p = 0,w; 5 typedef struct node 6 { 7 int num,y; 8 }st; 9 st q[1001];10 void 阅读全文
posted @ 2012-07-11 16:15 _雨 阅读(468) 评论(0) 推荐(0) 编辑
摘要: 刚开始把路径标记给取消了就一直TLEView Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<string.h> 4 int k[1001][1001],f[1001],n,m,a,b,flag,x; 5 void dfs(int x) 6 { 7 int j; 8 f[x] = 1; 9 if(flag == 1)10 return ;11 for(j = n ;j>=1 ; j-- )12 if(k[x][j] == 1&&f[j] == 0)13 ... 阅读全文
posted @ 2012-07-11 11:24 _雨 阅读(235) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1882搜索 递归回溯View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<math.h> 4 int q[21][21],flag,a[21],f = 0; 5 void dfs(int i, int n) 6 { 7 int j,k,p,l,m; 8 if(f == 1) 9 return ;10 if(i>n)11 {12 . 阅读全文
posted @ 2012-07-11 10:20 _雨 阅读(163) 评论(0) 推荐(0) 编辑