摘要: DescriptionWe remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formally, that is a way to reorder elements of the set. For example, one can define a permutation of the set {1,2,3,4,5} as follows: This record defines a permutation P as follows: P(1) = 阅读全文
posted @ 2014-03-31 20:05 同学少年 阅读(314) 评论(0) 推荐(0)
摘要: 方法一:辗转相除法优点:代码简单,容易写。缺点:开销大,用时间多。代码:int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}方法二:二进制算法优点:速度快。主要思想:前提:a>b,分情况讨论:1.a和b均为偶数,gcd(a,b)=2*gcd(a/2,b/2);2.a为偶数b为奇数,gcd(a,b)=gcd(a/2,b);3.a和b均为奇数,gcd(a,b)=gcd(a-b,b)代码:int gcd(int a,int b){ int t=1,c,d; while(a!=b) { if(a>=1; ... 阅读全文
posted @ 2014-03-31 18:04 同学少年 阅读(189) 评论(0) 推荐(0)