随笔分类 -  搜索

深搜_简单的深搜(HDU_1181)
摘要:选定 'b' 开头的单词,深搜到底,如遇 'm' 结尾,返回。#include #include #define M 1002char map[M][M];int flag[M],tot,re_flag;void dfs(int i){ char endCH = map[i][(int)strlen(map[i]) - 1]; if(endCH == 'm') { re_flag = 1; return ; } for(int j=0; j<tot; j++) { if(!flag[j] && endCH == ma... 阅读全文
posted @ 2013-08-16 17:17 lk1993 阅读(305) 评论(0) 推荐(0)
广搜_限制转弯次数[连连看](HDU_1175)
摘要:标准广搜限制转弯次数同广搜_限制转弯次数(HDU_1728)#include #include #include using namespace std;#define M 1002struct node { int x,y,turn; node(int _x,int _y,int _turn) { x = _x; y = _y; turn = _turn; }};int map[M][M],flag[M][M];int move[4][2] = {-1,0,0,1,1,0,0,-1};queue q;int n,m;int judge(int x,int... 阅读全文
posted @ 2013-08-13 17:06 lk1993 阅读(278) 评论(0) 推荐(0)
广搜_限制转弯次数(HDU_1728)
摘要:广搜限制转弯次数直线搜索当前位置的四个方向,把途中没有访问的点 turn 值 +1 入队。 说明:如果直线到达终点,则返回 true;如果四个方向都没有到达,则一定会转向,则退出队列中 turn值 +1 的位置;首先判断当前 turn ,如果超限制,则一定不会再有位置可以到达终点(队列中的点都是不递减的);如果没有,继续直线搜索当前位置的四个方向。#include #include #include using namespace std;#define M 102struct node { int x,y,turn; node(int _x,int _y,int _turn) ... 阅读全文
posted @ 2013-08-13 17:00 lk1993 阅读(251) 评论(0) 推荐(0)
深搜_方向搜索(HDU_1035)
摘要:需要注意特殊案例的是:最后走到入口出时,步数为 0 。#include #include #define M 12char move_map[4] = {'N','S','E','W'};int move_do[4][2] = {-1,0,1,0,0,1,0,-1};char map[M][M];int step[M][M];int row,col,in,re_step,re_round;int jud(int r, int c){ if(rrow-1 || ccol-1) return 0; return 1;}void dfs 阅读全文
posted @ 2013-08-11 19:31 lk1993 阅读(183) 评论(0) 推荐(0)
广搜_优先队列和记录搜索路径(HDU_1026)
摘要:#include #include #include #include using namespace std;#define M 105typedef struct Node{ int row,col,step,f_row,f_col,count; friend bool operator b.step; }} Node;const int move[4][2]={{-1,0},{1,0},{0,-1},{0,1}};char map[M][M];int n,m,sum;priority_queue Q;queue __Q;stack S,__S;void __cle... 阅读全文
posted @ 2013-04-21 20:03 lk1993 阅读(251) 评论(0) 推荐(0)
深搜_奇偶减枝(HDU_1010)
摘要:#include #include #include #include #define M 8char map[M][M];int move[4][2]={{-1,0},{1,0},{0,-1},{0,1}};int n,m,sx,sy,ex,ey,t,flag,count;void init(){ for(int i=0;i=0 && row=0 && col t-step) return; for(int i=0;i<4;i++) { int _row=row+move[i][0]; int _col=col+move[i]... 阅读全文
posted @ 2013-04-21 13:48 lk1993 阅读(142) 评论(0) 推荐(0)
深搜_八皇后(HDU_2553)
摘要:#include #include #define M 12int map[M][M],n,sum;int ini[M];int jud(int row,int col){ for(int i=1;in) { sum++; return ; } for(int i=1;i<=n;i++) { map[row][i]=1; if(jud(row,i)) dfs(row+1); map[row][i]=0; }}int main(int argc, char *argv[]){ #... 阅读全文
posted @ 2013-04-21 13:33 lk1993 阅读(210) 评论(0) 推荐(0)
深搜_素数环(HDU_1016)
摘要:1 #include 2 #include 3 4 #define M 21 5 6 int id[M],jud[M],n; 7 8 int is_prime(int n) 9 {10 for(int i=2;i*i=n)27 {28 show(); return ;29 }30 for(int i=1;i<=n;i++)31 {32 if(!jud[i] && is_prime(m+i))33 {34 id[cr+1]=i;35 ju... 阅读全文
posted @ 2013-04-20 22:13 lk1993 阅读(147) 评论(0) 推荐(0)