上一页 1 ··· 68 69 70 71 72 73 74 75 76 ··· 136 下一页
摘要: 7.2.1 生成1~n的全排列 #includeint A[100];// 输出1~n的全排列void print_permutation(int n, int* A, int cur) { int i, j; if(cur == n) { // 递归边界 for(i = 0; i #include#include#include#includeusing namespace ... 阅读全文
posted @ 2014-04-16 16:32 katago 阅读(640) 评论(0) 推荐(0)
摘要: 学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时) #include#include#include#include#includeusing namespace std;const int N=31;const int dl[]={-... 阅读全文
posted @ 2014-04-12 15:24 katago 阅读(389) 评论(0) 推荐(0)
摘要: bfs 最短路径 #include#include#include#include#include#includeusing namespace std;const int N=105;int n, m, rs, cs, rt, ct;typedef int A[N][N];A maze, vis, dist, last_dir;int dr[] = {-1,1,0,0};int dc... 阅读全文
posted @ 2014-04-12 13:47 katago 阅读(374) 评论(0) 推荐(0)
摘要: // 题意:输入标准国际象棋棋盘上的两个格子,求马最少需要多少步从起点跳到终点 BFS求最短路: bfs并维护距离状态cnt, vis记录是否访问过 #include#include#include#include#include#includeusing namespace std;int r1, c1, r2, c2;const int N=8;int vis[N][N];... 阅读全文
posted @ 2014-04-12 10:26 katago 阅读(743) 评论(0) 推荐(0)
摘要: // 题意:输入一个迷宫,从*开始遍历,把可达点标记为字符# 注意迷宫边界不规则,要用strlen判断。 #include#include#include#include#includeusing namespace std;const int maxn = 100 + 5;char maze[maxn][maxn];int dr[]={0, 0, -1, 1};int dc[]=... 阅读全文
posted @ 2014-04-10 17:46 katago 阅读(316) 评论(0) 推荐(0)
摘要: // 题意:给一个图案,其中'.'表示背景,非'.'字符组成的连通块为筛子。每个筛子里又包含两种字符,其中'X'组成的连通块表示筛子上的点 // 统计每个筛子里有多少个“X”连通块 思路:两次dfs //思路:先dfs找包含X和*的区域,再在*的区域中dfs X的个数#include#include#include#include#include#includeusing n... 阅读全文
posted @ 2014-04-10 14:52 katago 阅读(261) 评论(0) 推荐(0)
摘要: 技巧:遍历8个方向 for(int dr = -1; dr #include#include#include#includeusing namespace std;const int N=102;char buf[N][N];int m, n;int cnt;int dr[]={0, 0, 1, 1, 1, -1, -1, -1};int dc[]={1, -1, -1, 0, 1,... 阅读全文
posted @ 2014-04-04 16:57 katago 阅读(314) 评论(0) 推荐(0)
摘要: 注意点: 空树情况处理。 循环时候可以先判断符合条件,再递减: while(i-1>=0 && buf[r+2][i-1]=='-') i--; #include#include#include#include#includeusing namespace std;const int N=200+2;char buf[N][N];int n;//递归遍历并且输出以字符buf[... 阅读全文
posted @ 2014-04-04 16:47 katago 阅读(171) 评论(0) 推荐(0)
摘要: 我的解法: 建树,递归判断 #include#include#include#include#includeusing namespace std;struct Node { Node() { wl=wr=dl=dr=0; l=r=0; } int wl; int dl... 阅读全文
posted @ 2014-04-03 11:23 katago 阅读(221) 评论(0) 推荐(0)
摘要: 想学习一下编译原理部分再做 阅读全文
posted @ 2014-04-02 16:59 katago 阅读(191) 评论(0) 推荐(0)
上一页 1 ··· 68 69 70 71 72 73 74 75 76 ··· 136 下一页