摘要: 题目链接:http://poj.org/problem?id=1077经典八数码问题,作为A*与IDA*的入门题来说是很不错的。第一次学习A*与IDA*,代码参考了:http://www.cnblogs.com/liyongmou/archive/2010/07/19/1780861.html推荐一篇介绍A*算法的文章:http://hi.baidu.com/catro/item/4782da1769edbd721109b5e9英文原文:http://www.policyalmanac.org/games/aStarTutorial.htmA*算法的动画演示:http://www.java3z 阅读全文
posted @ 2013-04-23 15:08 冰鸮 阅读(221) 评论(0) 推荐(0)
摘要: 题目链接:http://poj.org/problem?id=1195二维树状数组的应用 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 const int MAXN = 1200; 6 int S; 7 int C[MAXN][MAXN]; 8 9 int lowbit( int x )10 {11 return x & -x;12 }13 14 void Add( int x, int y, int add )15 {16 int tpy;17 while ( x 阅读全文
posted @ 2013-04-15 21:05 冰鸮 阅读(205) 评论(0) 推荐(0)
摘要: 题目链接:http://poj.org/problem?id=3321刷POJ分类的时候遇到的题,只知道是树状数组,但是分支编号不连续,不晓得怎么用树状数组求和。后来看了解题报告才知道需要把分支通过DFS映射成编号连续的,记录每个子树的起始位置和终止位置,然后再用树状数组求和。即使明白了思路,代码实现上也还是有很多地方不理解。唉,数据结构学得实在有够糟糕……树的邻接表表示法每次往表头插入节点也让我费解了好半天Orz…… 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 cons 阅读全文
posted @ 2013-04-15 20:42 冰鸮 阅读(159) 评论(0) 推荐(0)
摘要: 题意:在不改变表达式的含义的情况下去除多余的括号,输入保证表达式是正确的。WA了整整一天,挺有意思的一题。给两组数据,我是主要就错在这两个地方了:2A-((A+A))A-(A+(A))结果都是A-(A+A)思路(优先级从上往下,一开始没考虑优先级的问题):1.开头的括号可去除2.括号内没有运算符的括号可去除3.括号前不是减号的括号可去除 1 #include <cstdio> 2 #include <cstring> 3 4 const int MAXN = 350; 5 6 struct node 7 { 8 char oper; 9 int addr;10 bo.. 阅读全文
posted @ 2013-04-02 12:21 冰鸮 阅读(182) 评论(0) 推荐(0)
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=443这题刚开始看的时候小郁闷了一下,入门经典把它放在难回溯的分类里,可我怎么也没觉得它跟回溯有啥关系,于是搁置了很久。题意:-是需要删除的文件,+是需要保留的文件,构造一个字符串,使它能一步删除所有需要删除的文件,同时不会误删需要保留的文件。思路:遍历所有需要删除的文件,相同位置字母相同的话,就填充那个字母,否则填充'?', 阅读全文
posted @ 2013-04-02 12:16 冰鸮 阅读(365) 评论(0) 推荐(0)
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2671分析:广搜,在加入Joe的起始位置之前,先把所有着火点加入队列。Joe只能到达没有障碍和火势控制的格子。 1 #include <cstdio> 2 #include <cstring> 3 4 const int MAXN = 1004; 5 const int dx[] = { -1, 1, 0, 0 }; 阅读全文
posted @ 2012-12-05 17:24 冰鸮 阅读(421) 评论(0) 推荐(0)
摘要: 题目链接:线段树,点修改。 1 #include <cstdio> 2 #include <cctype> 3 #define lson l, m, rt << 1 4 #define rson m + 1, r, ( rt << 1 ) | 1 5 6 const int MAXN = 100010; 7 const int INF = 2147483645; 8 9 int tree[ MAXN << 2 ]; 10 11 int min( int a, int b ) 12 { 13 return a < b ? a : 阅读全文
posted @ 2012-12-04 20:52 冰鸮 阅读(272) 评论(0) 推荐(0)
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=109&page=show_problem&problem=121题目描述:(待编辑)分析:(待编辑) 1 #include <cstdio> 2 #include <cstring> 3 4 const int MAXN = 12; 5 6 char num1[MAXN], num2[MAXN], sum[MAXN], str[100]; 7 int len1, len2, 阅读全文
posted @ 2012-11-08 23:36 冰鸮 阅读(482) 评论(0) 推荐(0)
摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=109&page=show_problem&problem=323题目描述:给定几个图形,问能否拼成一个4*4的矩形分析:这个题虽然放在难回溯里,但因为没有旋转翻转之类的操作,所以不是很难。一行一行的放就行了。 1 #include <cstdio> 2 #include <cstring> 3 4 const int MAXN = 10; 5 6 struct piece 阅读全文
posted @ 2012-11-06 21:25 冰鸮 阅读(186) 评论(0) 推荐(0)
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754线段树节点更新练习第四棵线段树……TUT……初始化的时候忘了把cnt设为0, RE了几次……=3= 1 #include <cstdio> 2 #include <cstring> 3 4 const int MAXN = 200000 + 10; 5 6 struct Node 7 { 8 int r, l; 9 int max;10 Node *l_child, *r_child;11 };12 13 Node Tree[MAXN + MAXN];14 int .. 阅读全文
posted @ 2012-10-27 14:25 冰鸮 阅读(157) 评论(0) 推荐(0)