摘要: 连块问题,输入矩阵后,逐点扫描,该点若没未标记过,计数器就+1,然后深度优先遍历,标记这一大块的通路,接着,继续扫点。#include #include using namespace std; const int maxn = 50 + 10; //设置最大长度 struct Tmap //定义结点数据类型,共有11种块,故开一个大小为12的数组,加1个四个方向都没有的结点 { int up; //结点的上面有没通路,有的话为1,没有为0 int down; //结点的下面有没通路,有的话为1,没有为0 int lef... 阅读全文
posted @ 2012-11-10 00:47 xiaodanding 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 这个问题的难处,对我而言在于计步数,开始时想在for(i = 0; i #include #include using namespace std; typedef struct Tdata //定义结点数据类型 { int x; int y; }data; int s[8][8]; //结点表:a1 对应 s[0][0],a8 对应 s[0][7] int vis[8][8]; //状态标记,0为未访问过,1为访问过 int cnt; //步数计数器 int dx[] = {-1, -2, -2, -1, 1,... 阅读全文
posted @ 2012-11-09 18:37 xiaodanding 阅读(151) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; int main() { int f[8][8] ={{0, 3, 2, 3, 2, 3, 4, 5}, //因为是8*8的方阵,不是很多数,所以枚举了所有的情况,就是从点(0, 0)到(x, y)最少要几步 {3, 2, 1, 2, 3, 4, 3, 4}, {2, 1, 4, 3, 2, 3, 4, 5}, {3, 2, 3, 2, 3, 4, 3, 4}, ... 阅读全文
posted @ 2012-11-01 01:34 xiaodanding 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 先分层,然后进行深度优先遍历。#include #include using namespace std; const int maxn = 30 + 10; //每组数据最多有30个数 int n, ok, C[maxn], a[maxn]; //n为每组数据的个数,ok标记是否有等式存在,C用来存路径,a为输入的数组 bool search(int *a, int x, int y, int v) //二分搜索,返回搜索成功与否 { int m; while(x v) y = m; else x = ... 阅读全文
posted @ 2012-11-01 01:32 xiaodanding 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 题目简单,但是要注意格式,本人提交5次,前4次均PE#include using namespace std; const int maxn = 10 + 10; int n, m, cnt; typedef struct datatype //定义数据类型 { int val; int num; }data; data a[maxn]; //要输入的数组 void dfs(int cur_sum, int last) //深度优先遍历 { int i; if(cur_sum == n) //当目前... 阅读全文
posted @ 2012-11-01 01:31 xiaodanding 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 小心格式,又试了一次PE!!!#include #include using namespace std; const int maxn = 1000 + 10; int a[maxn], b[maxn], d[maxn], G[maxn][maxn]; //a为外显子的起始点,b为外显子的终止点,d为路径长度,G为图 int n, first; //n为外显子的个数,first在输出时做标记(按格式输出的方法之一) int dp(int i) //核心代码,图记忆化搜索 { int& ans = d[i]; ... 阅读全文
posted @ 2012-11-01 01:29 xiaodanding 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 题意:输入一个整数1 >利用读入的数据递归建立4分树(注意边界条件:当矩阵只有1个元素即拆分到了1*1的矩阵时,肯定为0或者1,这时就是一个递归边界。),再对4分树进行层次遍历,最后转换成16进制数输出。#include #include #include using namespace std; const int maxn = 512 + 10; typedef struct Tquadtree //定义4分树的结点数据类型 { char val[3]; //val用来标明是00、01、1的状态 struct Tquadtree *q... 阅读全文
posted @ 2012-10-31 17:26 xiaodanding 阅读(196) 评论(0) 推荐(0) 编辑