04 2014 档案

排列组合生成算法
摘要:r排列生成: gen 递归层数d表示正在生成第d个元素。 vis记录是否出现过。 #include#include#includeusing namespace std;int n, r;int A[50], vis[50];//记录第i个元素是否生成过int cnt;int rer;void output(int r){ for(int i = 0; i #include... 阅读全文

posted @ 2014-04-30 16:27 katago 阅读(2977) 评论(0) 推荐(0) 编辑

729 - The Hamming Distance Problem
摘要:// 题意: // 输入两个整数N, H,按照字典序输出所有长度为N,恰好包含H个1的01串 // 规模:1#include const int maxn = 20;int N, H, bits[maxn];// 从bits[d]开始确定,已经用了c0个0和c1个1void gen(int d, int c0, int c1) { if(d == N) { if(c1 ... 阅读全文

posted @ 2014-04-28 17:07 katago 阅读(257) 评论(0) 推荐(0) 编辑

扑克牌型
摘要:比牌先比牌型,大的牌型大于小的牌型,牌型一般分为10种,从大到小为: 同花大顺(Royal Flush):最高为Ace(一点)的同花顺。 例: 同花顺(Straight Flush):同一花色,顺序的牌。 例: 四条(Four of a Kind,亦称“铁支”、“四张”或“炸弹”):有四张同一点数的牌。 例: 满堂红(Fullhouse,亦称“俘虏”、“骷髅”、“夫... 阅读全文

posted @ 2014-04-25 17:31 katago 阅读(2093) 评论(0) 推荐(0) 编辑

UVa11205 The Broken Pedometer
摘要:// 题意:有P个LED灯,以及N个字符,要求选出个数最少的LED灯,使得即使只有这些灯正常工作,也能区分出这N个字符 // 题意抽象:输入两个整数P, N以及N行P列的01矩阵,找少的列,能区分所有行 // 规模:P#include#include#include#include#includeusing namespace std;const int P=15;const i... 阅读全文

posted @ 2014-04-25 15:44 katago 阅读(231) 评论(0) 推荐(0) 编辑

Uva 10167 - Birthday Cake 暴力枚举 随机
摘要:Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them.Now we put the cake onto a Descartes coordinate. Its center is at (... 阅读全文

posted @ 2014-04-25 11:35 katago 阅读(358) 评论(0) 推荐(0) 编辑

7.5.3 八数码问题
摘要:bfs图的时候需要注意判重。 八数码状态数 9!=362880 ,如果用9维的vis,9^9=387420489,会有很大的浪费。 有三种方法来解决空间浪费问题: 1、编码解码 这里用cantor编码 typedef int State[9];const int MAXSTATE = 1000000;State st[MAXSTATE], goal;int dist[MAXSTAT... 阅读全文

posted @ 2014-04-24 16:05 katago 阅读(262) 评论(0) 推荐(0) 编辑

康托展开
摘要:http://zh.wikipedia.org/wiki/康托展开 http://www.nocow.cn/index.php/康托展开 http://blog.sina.com.cn/s/blog_4bf7b6580100l2zs.html http://www.skymoon.biz/?p=86 http://www.cnblogs.com/1-2-3/archive/2011/04/... 阅读全文

posted @ 2014-04-24 15:47 katago 阅读(195) 评论(0) 推荐(0) 编辑

7-3 倒水问题
摘要:例7-3 倒水问题。 有装满水的6升的杯子、空的3升杯子和1升杯子,3个杯子中都没有刻度。在不使用其他道具的情况下,是否可以量出4升的水呢? 方法如图7-7所示。 图7-7 倒水问题:一种方法是(6,0,0)→(3,3,0)→(3,2,1)→(4,2,0) 注意:由于没有刻度,用杯子x给杯子y倒水时必须一直持续到把杯子y倒满或者把杯子x倒空,而不能中途停止。 你的任务是解决一般性... 阅读全文

posted @ 2014-04-21 20:30 katago 阅读(808) 评论(0) 推荐(0) 编辑

排列生成算法注意事项
摘要:通过swap方式生成的全排列并不是字典顺序的: #include#include#include#include#includeusing namespace std;int A[20];int cnt;int recur;void perm(int cur, int n, int *A){ recur++; if(cur==n)//empty { ... 阅读全文

posted @ 2014-04-19 14:22 katago 阅读(193) 评论(0) 推荐(0) 编辑

7.3 子集生成
摘要:1、增量构造法: 一次选出一个元素放到集合中,由于集合中的元素是无序的,所以我们从小到大生成所有元素。每次选择的元素都要比之前的大。 如上图,生成 {1, 2, 3} 的子集过程中的解答树。 共有2^n个节点(8个),每个节点都是解。 2、位向量法 每次有选和不选两种情况 {1 ,2 ,3} 子集的解答数 总共有 1+2+4+ … +2^n= 2^(n+1)... 阅读全文

posted @ 2014-04-17 19:35 katago 阅读(214) 评论(0) 推荐(0) 编辑

7.2 枚举排列
摘要: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 阅读(634) 评论(0) 推荐(0) 编辑

UVa532 Dungeon Master 三维迷宫
摘要:学习点: 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 阅读(381) 评论(0) 推荐(0) 编辑

6.4.2 走迷宫
摘要: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 阅读(368) 评论(0) 推荐(0) 编辑

UVA 439 Knight Moves
摘要:// 题意:输入标准国际象棋棋盘上的两个格子,求马最少需要多少步从起点跳到终点 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 阅读(739) 评论(0) 推荐(0) 编辑

UVa784 Maze Exploration
摘要:// 题意:输入一个迷宫,从*开始遍历,把可达点标记为字符# 注意迷宫边界不规则,要用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 阅读(311) 评论(0) 推荐(0) 编辑

UVa657 The die is cast
摘要:// 题意:给一个图案,其中'.'表示背景,非'.'字符组成的连通块为筛子。每个筛子里又包含两种字符,其中'X'组成的连通块表示筛子上的点 // 统计每个筛子里有多少个“X”连通块 思路:两次dfs //思路:先dfs找包含X和*的区域,再在*的区域中dfs X的个数#include#include#include#include#include#includeusing n... 阅读全文

posted @ 2014-04-10 14:52 katago 阅读(258) 评论(0) 推荐(0) 编辑

UVa572 Oil Deposits DFS求连通块
摘要:技巧:遍历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 阅读(309) 评论(0) 推荐(0) 编辑

UVa10562 Undraw the Trees
摘要:注意点: 空树情况处理。 循环时候可以先判断符合条件,再递减: 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 阅读(164) 评论(0) 推荐(0) 编辑

UVa839 Not so Mobile
摘要:我的解法: 建树,递归判断 #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 阅读(218) 评论(0) 推荐(0) 编辑

327 - Evaluating Simple C Expressions
摘要:想学习一下编译原理部分再做 阅读全文

posted @ 2014-04-02 16:59 katago 阅读(183) 评论(0) 推荐(0) 编辑

UVa699 The Falling Leaves
摘要:// UVa699 The Falling Leaves // 题意:给一棵二叉树,每个节点都有一个水平位置:左儿子在它左边1个单位,右儿子在右边1个单位。从左向右输出每个水平位置的所有结点的权值之和。按照递归方式输入,-1表示空 树 // UVa699 The Falling Leaves// Rujia Liu// 题意:给一棵二叉树,每... 阅读全文

posted @ 2014-04-02 12:55 katago 阅读(835) 评论(0) 推荐(0) 编辑

UVa712 S-Trees
摘要:// UVa712 S-Trees// Rujia Liu// 题意:给一棵满二叉树,每一层代表一个01变量,取0时往左走,取1时往右走。给出所有叶子的值,以及一些查询(即每个变量的值),求最后到达的叶子的值// 算法:结点从上到下编号为1, 2, 3, ...则左走就是乘以2,右走是乘以2加1。第一个叶子的编号是2^n#include#includeusing namespace std;... 阅读全文

posted @ 2014-04-02 09:55 katago 阅读(931) 评论(1) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示