![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithms
文章平均质量分 74
weiyier
这个作者很懒,什么都没留下…
展开
-
zoj 1828 Fibonacci Numbers
稍微做了些修改,基本思想一致memset是对字节进行操作void *memset(void *s, int ch, size_t n); 函数解释:将s中前n个字节替换为ch并返回s;作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法。void *memcpy(void *dest, const void *src, int n);转载 2012-04-07 22:11:36 · 528 阅读 · 0 评论 -
dijkstra算法
in.txt:600 20 50 30 00 00 20 00 25 00 00 70 50 25 00 40 25 50 30 00 40 00 55 00 00 00 25 55 00 10 00 70 50 00 10 00out.txt: -1 20 45 30 70 80#include #include #include using names原创 2013-03-26 20:44:21 · 623 阅读 · 0 评论 -
POJ 1154
#include using namespace std;int x,y,max,temp,num[27],str[21][21];int step[8]={1,0,-1,0,0,1,0,-1};void dfs(int i, int j){ int a,b; for(int k=0;k<8;k+=2) { a= i+step[k]; b= j+step[k+1];原创 2013-03-20 16:08:25 · 490 阅读 · 0 评论 -
插入、归并、快速排序
public class Insert{ public static void main(String[] args) { Random rand = new Random(100); int[] a = new int[rand.nextInt(50)]; int i, key, j; for ( i = 0; i < a.length; i++) a原创 2012-04-05 21:27:07 · 681 阅读 · 0 评论 -
zoj 1589
/** 将输入的字母转化为0 ~25 直接的整数,通过数组进行运算 */#include #include using namespace std;#define N 5 //相当于定义一个无穷大数int a[26][26];int i,j;void init(){ for(i=0;i<26;i++) for(j=0;j<26;j++) if(i==j) a转载 2012-05-01 10:36:47 · 721 阅读 · 0 评论 -
求5000000以内的亲和数
两个数a和b,a的所有真因数之和等于b,b的所有真因数之和等于a,则称a,b是一对亲和数。如: 220的真因子是:1、2、4、5、10、11、20、22、44、55、110; 284的真因子是:1、2、4、71、142。伴随矩阵的思想很值得学习#include #include #define num 5000000int sum[num];int转载 2012-04-12 21:46:43 · 671 阅读 · 0 评论 -
URAL 1013. K-based Numbers. Version 3
题目: 先定义有效的数:第一位不能为0,不能存在相邻的0.问N位K进制数有这样的有效数的数目.递归公式: f(k)=(k-1)*(f(k-1)+f(k-2)) 对k位的数进行分析,第一位有(k-1)种选择,第二位如果是0,则有f(k-2)种情况,第二位如果非0,正好有f(k-1)种情况.#include #include #include const int MAX = 30转载 2012-04-13 11:16:20 · 685 阅读 · 0 评论 -
左旋转字符串
#include #include int main(){ int i,d,t,m; char a[10]; memset(a,0,sizeof(a)); scanf("%s %d",a,&d); m=strlen(a); d%=m; while(d--) { /** 左移 */ /* t=a[0]; for(i=0;i<m-1;i++) a[i]=a[i+1原创 2012-04-12 10:45:33 · 618 阅读 · 0 评论 -
POJ 2192-zipper(动态规划)
#include #include char a[210],b[210],c[420]; int dfs(int x, int y){ if(x==-1&&y==-1) return 1; if(x>=0 && a[x]==c[x+y+1]) if(dfs(x-1,y)) return 1; if(y>=0&&b[y]==c[x+y+1]) if(dfs(x转载 2012-04-12 17:32:08 · 667 阅读 · 0 评论 -
连续数之和为x,求共有几对
微软有一道面试题,问1000以内有几对连续数之和为1000,如下:例如:输入:15输出:1 2 3 4 5 4 5 6 7 8#include #include using namespace std;int main(){ int i,x,j,min,max,flag; while(scanf("转载 2012-04-11 11:29:53 · 421 阅读 · 0 评论 -
zoj 1962 || poj 2413 How many Fibs?
#include #include #include #include using namespace std;int f[500][110];int x;int len[500],nn,bb;int find(int s[],int n){ for(int i=1;i<500;i++) { if(len[i]<n) continue; if(len[i]=转载 2012-04-08 22:11:27 · 649 阅读 · 0 评论 -
Reservoir Sampling 蓄水池抽样 海量数据不知道总数只能遍历一次随机抽样问题
问题起源于编程珠玑Column 12中的题目10,其描述如下: How could you select one of n objects at random, where you see the objects sequentially but you do not know the value of n beforehand? For concreteness, how wou转载 2013-07-04 20:31:40 · 990 阅读 · 0 评论