随笔分类 -  搜索

摘要:《对弈程序基本技术》专题 最小-最大搜索:http://www.xqbase.com/computer/search_minimax.htm《对弈程序基本技术》专题 Alpha-Beta搜索 :http://www.xqbase.com/computer/search_alphabeta.htmWikipedia MinMax :http://en.wikipedia.org/wiki/MinimaxWiki Alpha–beta pruning :http://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruningMinmax Explained:h 阅读全文
posted @ 2013-01-25 19:19 AC_Von 阅读(4015) 评论(0) 推荐(2)
摘要:搜索较麻烦的搜索题目训练poj1069,poj3322,poj1475,poj1924,poj2049,poj3426广搜的状态优化poj1768,poj1184,poj1872,poj1324,poj2046,poj1482深搜的优化poj3131,poj2870,poj2286较麻烦的搜索题目训练poj 3322感觉这题应该归类到模拟题。。。bfs&&priority_queue直接模拟就行。昨晚写了一个版本,因为状态记录的太多了,MLE一次。发现总共有三种形状,每种形状可以用一个坐标加一个标号表示。比如约定立着的用(x, y, 0)表示,横着的为(x, y), (x, y 阅读全文
posted @ 2012-11-26 19:38 AC_Von 阅读(288) 评论(0) 推荐(0)
摘要:第一次接触A*,感觉好神奇。。启发函数:f(x) = g(x) + h(x);比如初始状态为s,目标状态为tg(x)表示从s到达状态x所消耗的代价h(x)表示从x到达t所估算的代价g'(x)表示s -> x可能出现的最小代价h'(x)表示x -> t可能出现的最小代价g(x) >= g'(x);h(x) <= h'(x);好吧,上面全是概念。。。当g(x) 为0时,A*就成了bfs,当h(x)为0时,A*就成了dfs。所以。。。启发函数的选择直接影响到A*算法的性能。大概的说说我对A*算法运算过程的理解吧:基本就是bfs形式,不过要用到优 阅读全文
posted @ 2012-07-17 10:06 AC_Von 阅读(4424) 评论(1) 推荐(0)
摘要:最优化剪枝和可行性剪枝poj1699搜索的技巧和优化poj3411, poj1724记忆化搜索poj3373,poj1691最优化剪枝和可行性剪枝POJ 1699对这题无语了,爆搞TLE,加一个怎么也没想到的减枝47MS...规模并不大,可以直接dfs,需要预处理一下,add[i][j]表示第j号串加在第i号串上增加的长度。。。这个计算的时候要注意。本菜就错在这上边wa了一上午!。搜索的技巧和优化poj 3411题意:有m条路,N个顶点。从ai到bi的路要付费,付费有两种方式:1、比如之前去过ci,则可以在ci预付pi的费用。2、到达bi以后再付费,这样的费用是ri。求从1到N共的最小付费.. 阅读全文
posted @ 2012-05-16 09:24 AC_Von 阅读(461) 评论(0) 推荐(0)
摘要:两个典型的例题:POJ 1753, POJ 2965;POJ 1753 状态转移:1 int Flip(int pos, int i) {2 pos ^= (1<<i);3 if(i+4 < 16) pos ^= (1<<(i+4));4 if(i-4 >= 0) pos ^= (1<<(i-4));5 if(i%4+1<4) pos ^= (1<<(i+1));6 if(i%4-1>=0) pos ^= (1<<(i-1));7 return pos;8 }POJ 2965 状态转移:(这题的输出结果是不是要 阅读全文
posted @ 2012-02-24 20:46 AC_Von 阅读(363) 评论(0) 推荐(0)
摘要:/*从昨天下午看这道题,一直到现在,以前做过一个类似连连看的题,跟这题差不多,就按那个思路写了,一步一步的搜,我晕,把bfs写暴也没能AC。上午请教牛人,说bfs时不要搜步数,直接搜直线数。就是一条路走到头,不撞南墙不死心(大体是这个意思^_^)。然后就是正常的bfs写法。入队列,出队列。。。 ps:注意标点符号T_T.*///My Code:#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int N = 80;struct node{ int x 阅读全文
posted @ 2011-10-22 15:36 AC_Von 阅读(587) 评论(0) 推荐(0)
摘要:/*这题应该属于水题吧,基本不用什么大的处理,看懂题意就行。直接n次dfs,找出最大的length*///My Code: 16MS#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 30;int map[N][N];bool vis[N][N];int n;int ans;void dfs(int now, int t){ int f, i; for(f = 1, i = 0; i < n; i++){ if(vis[now][ 阅读全文
posted @ 2011-10-21 14:57 AC_Von 阅读(252) 评论(0) 推荐(0)
摘要:/*不明白为什么Ural把这题归到game里边,难到是因为这题是个游戏。。。很水的一道题,纠结了两天,以前没有接触过位压缩,估计学过位压缩的童鞋能够把这题直接秒掉,Orz各位做题神速的童鞋。。。 wwww wwww wwwb wwbb可以用二进制表示为:1100|1000|0000|0000;也就是说4*4方格里所有状态都可以用16位二进制表示,转成十进制后为0或者65535就完成了游戏。*///My Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std; 阅读全文
posted @ 2011-10-21 10:37 AC_Von 阅读(416) 评论(0) 推荐(0)
摘要:/*简单DFS,开始这题想复杂了,不知道用dfs还是bfs甚至都想写dijkstra,后来一狠心写了个dfs,1Y了,^_^ ,可能题目的数据比较若吧,呵呵,感觉主要还是把图抽出来这地方,有点像模拟题了。输出是加了一个pre[]存放当前结点的前驱,然后把pre[]包含的结点信息入栈,然后出栈好了。*///My Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 300;char str[110][N];int map[110] 阅读全文
posted @ 2011-10-20 11:32 AC_Von 阅读(259) 评论(0) 推荐(0)
摘要:写了整整一天,到晚上才出过样例,然后各种wa, tle ,ole !!!code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 11;char map[N][N];int hr[N][N];int hc[N][N];int hx[3][3][N];int z;void dfs(int i, int j){ int x, y, k, l; if( i < 0 && z){ for(k = 0; k < 9 阅读全文
posted @ 2011-10-19 20:23 AC_Von 阅读(208) 评论(0) 推荐(0)
摘要:/*感觉我的做法很麻烦,一个只存+-符号的数组, 一个存所有操作符的队列,再来一个队列存操作数(比如1,2, 1011(10.11的情况))。然后就是暴搜。。。*//*My Code: 297MS*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 50;char opr2[N];char opr[N];int opn[N];int cnt, n;void dfs(int p, int p2, int m, int sum, int 阅读全文
posted @ 2011-10-18 21:20 AC_Von 阅读(387) 评论(0) 推荐(0)
摘要:刚拿到这题时很纠结,没有思路。后来想了一天,问了问高手终于把思路整理出来。思路:三个瓶子,无非就是6种倒法,按杯子体积从大到小定义为s, m, n。则6种倒法分别是:s -> m, s -> n, m -> n, m -> s, n -> m, n -> s;加一个标记变量,标记当前状态已经出现过。将没出现过的状态入队列,剩下的就是bfs的事了。。。My Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const 阅读全文
posted @ 2011-09-02 21:49 AC_Von 阅读(285) 评论(0) 推荐(0)
摘要:这题用bfs做的,总结出来一条真理!在用bfs时,如果要引用结构体定义中的值,一定加中间变量,不要直接在上边操作。思路:直接用bfs找终点,如果中途遇到map[i][j] == 4的点,就把time置为6, 把走过的map[i][j] == 4的点标记为0;My Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct nightmare{ int i; int j; int t; int step;}q[10000];int d[4][2] = 阅读全文
posted @ 2011-09-02 19:33 AC_Von 阅读(220) 评论(0) 推荐(0)
摘要:此题做的相当爽,为什么爽呢,因为。。。连带TLE, RE, WA。总共错了11次。。。有一个地方没考虑清楚,然后再怎么剪枝都WA,最后ZZ一句话惊醒梦中人,总于A了。思路:这题要求方向改变次数。用一个变量记录上一次的方向,与下一次向比较,如果不同则加1。My Code:#include <iostream>#include <cstdio>#include <cstring>#define ud 1; //标记上下方向#define lr 2; //标记左右方向using namespace std;int map[1005][1001]; //存放每次询问 阅读全文
posted @ 2011-09-02 15:56 AC_Von 阅读(310) 评论(0) 推荐(0)
摘要:开始没整明白,还想用dfs递归求解,后来看了看解题报告的思路(貌似这题可以用dp),bfs一遍,用一个best[i]存放到i的最优解,最后直接输出best[k]就行。第一次队列数组开小(还是不想用<queue>)了,WA了一次。。。#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 100007;int q[N*10];int best[N];int n, k;void bfs(){ int f = 0, r = 0, x, 阅读全文
posted @ 2011-08-24 11:35 AC_Von 阅读(192) 评论(0) 推荐(0)
摘要:代码+注释:#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int N = 100;int s[N];bool used[N];int cmp(int a, int b){ return a > b;}bool dfs(int n, int u, int left, int len){//n是木棍的总数//u是未被拼到长度为len的原始木棍中木棍数目//left是当前正在拼的木棍的剩余长度//len是正在尝试的原始木棍的长度 if(lef 阅读全文
posted @ 2011-08-24 09:59 AC_Von 阅读(222) 评论(0) 推荐(0)
摘要:纠结一晚上,注意细节啊!!!(看到有很多解题报告都用<queue>,我不太喜欢用STL的东西。。。)My Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 51;struct node{ int x; int y; int z; int t;}q[N*N*N];int d[6][3] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, -1}, {0, 阅读全文
posted @ 2011-08-22 22:05 AC_Von 阅读(347) 评论(0) 推荐(0)
摘要:剪枝不好想啊。。。a到b别管绕多远,所走过的格子数的奇偶性和它俩最短路的奇偶性相同。代码。。。#include <stdio.h>#include <math.h>int d[4][2] = {{0,1},{0,-1},{-1,0},{1, 0}};int flag;int n, m, t, flag;int di, dj;char map[9][9];void dfs(int si, int sj, int cnt){ if(si == di && sj == dj && cnt == t) flag = 1; if(flag) ret 阅读全文
posted @ 2011-08-02 10:27 AC_Von 阅读(256) 评论(0) 推荐(1)
摘要:邻接表实现图的深度遍历,纠结的问题啊。。。。。View Code #include <stdio.h>#include <malloc.h>#define MAX 100typedef struct arcnode/*表节点*/{ int adjvex; /*邻接点*/ struct arcnode *nextarc;/*指向下一条弧的指针*/}arcnode;typedef struct vnode /*头结点*/{ int data; /*定点信息*/ arcnode * firstarc; /*指向第一个依附该顶点的弧的指针*/}vnode, adjlist[MA 阅读全文
posted @ 2011-07-29 19:59 AC_Von 阅读(725) 评论(0) 推荐(0)
摘要:转载:http://blog.csdn.net/akof1314/article/details/4388304 图的存储方式可以用邻接矩阵来表示,我们假定顶点序号从0开始,即图G的顶点集的一般形式是V(G)={v0,vi,…,Vn-1}。以下代码测试过,为图的邻接矩阵表示方式。测试结构如下(含测试数据):View Code /************************************************************************//* 图的邻接矩阵存储结构 *//********************************************. 阅读全文
posted @ 2011-07-28 08:10 AC_Von 阅读(1020) 评论(0) 推荐(0)