随笔分类 -  搜索

摘要:http://poj.org/problem?id=3083题意:迷宫问题,求从进入点到出口,分别按靠左边,右边和最短距离到达出口所学要的步数;思路:用dfs求得靠左靠右走到达出口的步数,用bfs求最短最少到达出口的步数;代码:View Code #include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <queue>using namespace std;int xx[6] = 阅读全文
posted @ 2012-02-29 22:04 LT-blogs 阅读(265) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3295题意:判断一个表达式的值是否都为1,p, q, r, s, and t 为取值为true或false的元素,K, A, N, C, E则为对应的运算法则;思路:从后往前递推,并且要尝试所有的取值可能;代码:View Code #include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cstdlib>#include <stack>using namespa 阅读全文
posted @ 2012-02-25 19:23 LT-blogs 阅读(182) 评论(0) 推荐(0)
摘要:题意和2965差不多,思路也是一样的:链接:2965代码:View Code #include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;int s[16] ={ 0xc800,0xe400,0x7200,0x3100, 0x8c80,0x4e40,0x2720,0x1310, 0x08c8,0x04c4,0x0272,0x0131, 0x008c,0x004e,0x0027,0x0013};int result = 1 阅读全文
posted @ 2012-02-23 20:30 LT-blogs 阅读(157) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2965 位运算+搜索题意:将下图这样的图案都变成减号,规则每次改变一个,这一个的行和列都会发生转换;思路:总共有2^16的情况,全部都搜一遍,用位运算一次改变一行和一列;-+-----------+--搜索题解:View Code #include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;int result = 17;int path = 0;int s[16] 阅读全文
posted @ 2012-02-23 20:00 LT-blogs 阅读(148) 评论(0) 推荐(0)
摘要:http://acm.sdut.edu.cn/web/problem.php?action=showproblem&problemid=1566这是上个星期测试赛的最后一个题目,那天真是悲剧了,一个也没做出来,;思路:采用VONGONG的思路做的,用bfs搜索来找:View Code #include<cstdio>#include<iostream>#include<algorithm>#include<string.h>using namespace std;int map[55][55];int p(int w){ int temp 阅读全文
posted @ 2011-12-07 19:31 LT-blogs 阅读(311) 评论(0) 推荐(0)