andre_joy

导航

2012年7月12日

hdu 1372

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1372题意:按照国际象棋规则马最少几步从开始点走到终点。mark:bfs,仔细。代码:#include <stdio.h>#include <string.h>int a[100][2],d[8][8];char p[5],q[5];void bfs(){ int front = 0,rear = 1,m,n; d[p[0]-'a'][p[1]-'0'-1] = 0; a[0][0] = p[0]-'a'; a[0][1] = p[ 阅读全文

posted @ 2012-07-12 22:40 andre_joy 阅读(274) 评论(0) 推荐(0) 编辑

hdu 2717

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=2717题意:三种走法+1,-1,*2,最少几步到指定点。mark:wa了好多次。bfs算法,注意临界条件。代码:#include <stdio.h>#include <string.h>int a[100010],d[100010],n,k;void bfs(){ int front = 0,rear = 1,nn; a[0] = n; d[n] = 0; while(front != rear) { nn = a[front++]; if(nn... 阅读全文

posted @ 2012-07-12 22:08 andre_joy 阅读(188) 评论(0) 推荐(0) 编辑

POJ 1579

摘要: 地址:http://poj.org/problem?id=1579题意:按照题目要求递归。mark:直接递归肯定是TLE的。记忆化深度搜索。代码:#include <stdio.h>int s[21][21][21];int w(int a, int b, int c){ if(a <= 0 || b <= 0 || c <= 0) return 1; if(a > 20 || b > 20 || c > 20) return s[20][20][20] = w(20, 20, 20); if(s[a][b][c]) return s[a][b] 阅读全文

posted @ 2012-07-12 18:50 andre_joy 阅读(165) 评论(0) 推荐(0) 编辑

hdu 1241

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1241题意:跟2952一样,只不过多加了四个方向。mark:多加了四个方向之后,遍历的时候不用打表了,可以直接枚举。代码:#include <stdio.h>char a[110][110];int m,n;void ss(int x, int y){ int i,j,xx,yy; a[x][y] = '1'; for(i = -1; i < 2; i++) for(j = -1; j < 2; j++) { xx = x+i; ... 阅读全文

posted @ 2012-07-12 18:25 andre_joy 阅读(222) 评论(0) 推荐(0) 编辑

hdu 2952

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=2952题意:找分开的#最多的片数mark:dfs.同1312一样。代码:#include <stdio.h>char a[110][110];int h,w;void ss(int x, int y){ int tab[4][2] = {0,1,0,-1,-1,0,1,0}; int i,xx,yy; a[x][y] = '1'; for(i = 0; i < 4; i++) { xx = x+tab[i][0]; yy = y+tab[i][1... 阅读全文

posted @ 2012-07-12 18:04 andre_joy 阅读(147) 评论(0) 推荐(0) 编辑

hdu 1312

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1312题意:找可以到达的黑格子。mark:dfs..代码:#include <stdio.h>char a[25][25];int sum;void ss(int w, int h, int x, int y){ if(y > 0 && a[x][y-1] == '.') { a[x][y-1] = '1'; sum++; ss(w, h, x, y-1); } if(x < h-1 && a[x+1][y] == 阅读全文

posted @ 2012-07-12 17:48 andre_joy 阅读(133) 评论(0) 推荐(0) 编辑

UVa 10071

摘要: 地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1012题意:给定t时刻速度v,求2t时刻位移。mark:化简位移公式。代码:#include <stdio.h>int main(){ int a,b; while(~scanf("%d%d", &a, &b)) printf("%d\n", 2*a*b); return 0;} 阅读全文

posted @ 2012-07-12 16:31 andre_joy 阅读(92) 评论(0) 推荐(0) 编辑

UVa 10055

摘要: 地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=996题意:给军官和敌人的士兵数,求两个人士兵数的差值。mark:UVa第一题,wa了5次。。学到两点! 1.unsigned [0,2^32-1],signed [-2^31, 2^31-1]。 2.vice versa 翻译为 反之亦然。代码:#include <stdio.h>int main(){ long long a,b; while(scanf(&qu 阅读全文

posted @ 2012-07-12 15:53 andre_joy 阅读(149) 评论(1) 推荐(0) 编辑

hdu 2189

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=2189题意:中文……mark:母函数求解。参见http://baike.baidu.com/view/2415279.htm代码:#include <stdio.h>#include <string.h>int a[35] = {2, 3, 5}, b[2][151];int pd(int m){ int i; for(i = 0; a[i]*a[i] <= m; i++) if(m%a[i] == 0) return 0; return 1;}int main(){ .. 阅读全文

posted @ 2012-07-12 00:02 andre_joy 阅读(177) 评论(0) 推荐(0) 编辑