摘要: 1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 5 using namespace std; 6 7 int Prime(int x) 8 { 9 int i=2,flag = 1;10 while(i<=sqrt(double(x)) && flag==1)11 {12 if(x%i==0)13 {14 flag = 0;15 break;16 }17 i++;18 }19 ... 阅读全文
posted @ 2011-08-24 15:25 zhongya 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 1 #include<iostream> 2 #include<cstdio> 3 4 using namespace std; 5 6 char s[7][7]; 7 int n, m,wall,ok; 8 int visit[7][7]; 9 int si, sj;10 int dir[4][2] = {-1,0,0,1,1,0,0,-1};//四个方向,这是做DFS常用的方法,要谨记。11 12 int dfs(int x,int y,int num)13 {14 if(num==n*m-wall-1) 15 return ok = 1;16 for ... 阅读全文
posted @ 2011-08-24 15:22 zhongya 阅读(191) 评论(0) 推荐(1) 编辑
摘要: 1 #include<iostream> 2 #include<cstdio> 3 4 using namespace std; 5 6 char s[7][7]; //将变量名放在主函数外面为了递归调用时方便。 7 int n,m,t,ok; 8 int visit[7][7]; 9 int dir[4][2] = {-1,0,0,1,1,0,0,-1};//分为查找的四个方向10 int Si,Sj,di,dj;11 12 int dfs(int x,int y,int step)13 {14 if(ok == 1) return 0; //ok==1表示找到出口了 阅读全文
posted @ 2011-08-24 15:18 zhongya 阅读(247) 评论(0) 推荐(1) 编辑
摘要: 1 #include<cstdio> 2 #include<iostream> 3 #include<queue> 4 5 using namespace std; 6 7 queue<int>q; 8 int main() 9 {10 int i, w, h, k, j;11 int visit[21][21];12 char s[21][21];13 14 while(scanf("%d%d", &w, &h) != EOF)15 {16 if(w==0 && h==0) break;17 阅读全文
posted @ 2011-08-22 16:07 zhongya 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 需要用到一些数学公式:(a+b)%m = (a%m + b%m)%m(a*b)%m = (a%m * b%m)%m这是利用它的余数来优化,从而减少了计算量 1 #include<stdio.h> 2 #include<string.h> 3 4 int main() 5 { 6 int i, ncases, num, m; 7 long long k, sum; 8 char n[101]; 9 10 while(scanf("%d", &ncases) != EOF)11 {12 while(ncases--)13 ... 阅读全文
posted @ 2011-08-21 23:19 zhongya 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 3 int num[21][21][21] = {0}; 4 5 int w(int a,int b,int c) 6 { 7 if (a<=0 || b<=0 || c<=0) return 1; 8 if(a>20 || b>20 || c>20) return w(20,20,20); 9 if(num[a][b][c]) return num[a][b][c];10 11 if(a<b && b<c) return num[a][b][c] = w(a,b,c-1)+ 阅读全文
posted @ 2011-08-21 21:43 zhongya 阅读(257) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 int w[21][21][21]; 3 int main() 4 { 5 int a,b,c; 6 7 for(a=0; a<21; a++) 8 for(b=0; b<21; b++) 9 for(c=0; c<21; c++)10 {11 if(a<=0||b<=0||c<=0)12 w[a][b][c] = 1;13 else if(a<b && b<c)14 w[a][b][c] = w[a][b][c-... 阅读全文
posted @ 2011-08-21 21:40 zhongya 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<math.h> 5 #define N 2147483648 6 7 int cmp(const void *a,const void *b) 8 { 9 return *(int *)a - *(int *)b;10 }11 12 int main()13 {14 int k=0, i, j;15 int a[50000]; //数组最大不超过5万个,因为5万的平方大于N了。16 17 ... 阅读全文
posted @ 2011-08-21 11:23 zhongya 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 1 #include<stdio.h> 2 #include<string.h> 3 #define N 101 4 5 int main() 6 { 7 int ncases, i, sum1, sum2; 8 int len1, len2, j; 9 char a[N], b[N];10 11 while(scanf("%d",&ncases) != EOF)12 {13 for (i=1; i<=ncases; i++)14 {15 scanf("%s%s",a,b);16 ... 阅读全文
posted @ 2011-08-20 20:59 zhongya 阅读(132) 评论(0) 推荐(1) 编辑
摘要: 1 #include<iostream> 2 #include<queue> 3 #define MAXV 100000 4 using namespace std; 5 int sign[100001],len[100001]; //sign是用来做标记的,len用来走到重点需步长 6 int main() 7 { 8 int N, K, y; 9 cin >> N >> K;10 queue<int>Q;11 Q.push(N);12 len[N] = 0;13 while(!Q.empty())14 {15 ... 阅读全文
posted @ 2011-08-19 17:23 zhongya 阅读(145) 评论(0) 推荐(0) 编辑