摘要: 递归算法:#include <iostream>using namespace std;int i=1;void move(int n,char a,char b){//move n from a to b cout<<"#"<<i++<<". "<<n<<": "<<a<<"->"<<b<<endl;}void hanoi(int n,char x,char y,char z){ if(n 阅读全文
posted @ 2011-04-21 01:00 wwwwwwwww11we 阅读(272) 评论(0) 推荐(1) 编辑
摘要: //print calender#include <iostream>#include <iomanip>using namespace std;void printMonth(int year,int month);void printMonthTitle(int year,int month);void printMonthName(int month);void printMonthBody(int year,int month);int getStartDay(int year,int month);int getTotalNumberOfDays(int ye 阅读全文
posted @ 2011-04-21 00:40 wwwwwwwww11we 阅读(332) 评论(0) 推荐(0) 编辑
摘要: //To determine a number is prime or notint prime(int n){ if(n==1) return -1; if(n==2) return 1; else if(n%2==0) return 0; else{ for (int i=3;i<=sqrt(n);i+=2) if(n%i==0) return 0; return 1; }} 阅读全文
posted @ 2011-04-21 00:37 wwwwwwwww11we 阅读(146) 评论(0) 推荐(0) 编辑
摘要: #include <fstream>#include <cmath>#define MAX 8using namespace std;ofstream cout("out");int queens[MAX];int sum=0;void print();void placequeens(int i);bool isValid(int n);void print(){ for (int i=0;i<MAX;i++){ for (int j=0;j<MAX;j++){ if(j==queens[i]) cout<<"Q 阅读全文
posted @ 2011-04-21 00:35 wwwwwwwww11we 阅读(171) 评论(0) 推荐(0) 编辑
摘要: /******************* Base Transform *******************/#include <iostream>#include <cstring>#include <string>using namespace std;string str;int start[1000],ans[1000],res[1000];//被除数,商,余数//转换前后的进制int oldBase,newBase;int change(){//各个数位还原为数字形式 int len=str.length(); start[0]=len; for 阅读全文
posted @ 2011-04-21 00:32 wwwwwwwww11we 阅读(273) 评论(0) 推荐(1) 编辑
摘要: //print factorial#include <iostream>#include <cstring>using namespace std;const int maxn=3000;int main(){ int nCases; cin>>nCases; for(int i=1;i<=nCases;i++) { int fac[maxn]; int j,n; cin>>n; memset(fac,0,sizeof(fac)); fac[0]=1; for(i=2;i<=n;i++) { int c=0; for(j=0;j< 阅读全文
posted @ 2011-04-21 00:29 wwwwwwwww11we 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 来自http://blog.csdn.net/MasterLuo/archive/2009/09/21/4575412.aspx扩展的欧几里德算法是求如a * x + b * y = (a, b) 这样的整数解的,可以仿照欧几里德算法得出答案。程序如下:/***扩展的欧几里德算法a*x + b*y = Gcd(a,b)的一组整数解,结果存在x,y中***/void extend_gcd(long long a, long long b, long long& x, long long &y) { if(b == 0) { x = 1; y = 0; return; } exte 阅读全文
posted @ 2011-04-21 00:22 wwwwwwwww11we 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 转载自 http://www.cnblogs.com/Knuth/archive/2009/09/04/1559949.html好文章,整理收藏。1.费马小定理:有N为任意正整数,P为素数,且N不能被P整除(显然N和P互质),则有:N^P%P=N(即:N的P次方除以P的余数是N) 或 (N^(P-1))%P=1互相变形:原式可化为:(N^P-N)%P=0(N*(N^(P-1)-1))%P=0所以,N*(N^(P-1)-1)是N和P的公倍数又因为 N与P互质,而互质数的最小公倍数为它们的乘积所以一定存在正整数M使得等式成立:N*(N^(P-1)-1)=M*N*P所以N^(P-1)-1=M*P因为 阅读全文
posted @ 2011-04-21 00:17 wwwwwwwww11we 阅读(1006) 评论(0) 推荐(2) 编辑