![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
搜索(bfs+dfs)
搜索
Learning_is_endless
天道酬勤 功到自成
展开
-
棋盘问题(简单深搜)
棋盘问题在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8...原创 2017-09-23 12:40:34 · 468 阅读 · 0 评论 -
N皇后问题 HDU - 2553(dfs)
N皇后问题 HDU - 2553在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 你的任务是,对于给定的N,求出有多少种合法的放置方法。 Input共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。Output共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。Sampl...原创 2018-05-23 22:15:14 · 182 阅读 · 0 评论 -
dfs最短路模板
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[51][51],vis[51][51];//a数组储存地图,vis数组标记有没有走过,防止重复走。int n,m,p,q,Min=99999999;...原创 2018-05-23 23:07:52 · 554 阅读 · 0 评论 -
Prime Ring Problem HDU - 1016 (dfs、(素数筛模板))
Prime Ring Problem HDU - 1016 A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be ...原创 2018-05-24 09:28:42 · 136 阅读 · 0 评论 -
Find a way HDU - 2612 (bfs)
Find a way HDU - 2612 Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki. Yifenf...原创 2018-06-08 08:50:51 · 177 阅读 · 0 评论 -
Rescue ZOJ - 1649 (bfs 优先队列)
Rescue ZOJ - 1649 Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison.Angel's...原创 2018-06-09 08:53:53 · 268 阅读 · 0 评论 -
Fire Net ZOJ - 1002 (dfs)
Fire Net ZOJ - 1002 Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.A blockhouse i...原创 2018-06-09 21:40:08 · 193 阅读 · 0 评论 -
Borg Maze POJ - 3026(bfs+最小生成树)
Borg Maze POJ - 3026The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. The Borg collective is the term used to describe the group consciousness of ...原创 2018-07-19 15:00:51 · 291 阅读 · 0 评论 -
水陆距离 HihoCoder - 1478(bfs+思维)
水陆距离 HihoCoder - 1478给定一个N x M的01矩阵,其中1表示陆地,0表示水域。对于每一个位置,求出它距离最近的水域的距离是多少。 矩阵中每个位置与它上下左右相邻的格子距离为1。Input第一行包含两个整数,N和M。以下N行每行M个0或者1,代表地图。数据保证至少有1块水域。对于30%的数据,1 <= N, M ...原创 2018-07-29 19:10:27 · 500 阅读 · 0 评论 -
Fire! UVA - 11624 (bfs)
Fire! UVA - 11624 题目链接https://cn.vjudge.net/problem/UVA-11624 题意:J是人,只有一个,F是火可以有多个,#是墙,‘.’是人和火都能走的地方,问人走出边界需要几步思路:bfs(好久不写搜索了,手好生。。。),之前被卡住是在判断人和墙同时到达该怎么判断,很明显,同时到达一个地方是不行的,我之前是先让J入队列,不是很好判断...原创 2018-10-22 22:42:07 · 150 阅读 · 0 评论 -
Fire Game FZU - 2150 (bfs)
Fire Game FZU - 2150 Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just ...原创 2018-10-23 11:20:10 · 2910 阅读 · 0 评论 -
哈密顿绕行世界问题 HDU - 2181(dfs)
哈密顿绕行世界问题 HDU - 2181一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市。 Input前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每行有1个数m,m<=20,m>=1.m=0退出. Output输出从第m个城市出发经过每个城市1次又回到m的所有路线,如...原创 2018-10-27 10:40:34 · 170 阅读 · 0 评论 -
Knight Moves POJ - 1915 (bfs入门)
Knight Moves POJ - 1915 Background Mr Somurolov, fabulous chess-gamer indeed, asserts that no one else but him can move knights from one position to another so fast. Can you beat him? The Problem You...原创 2018-06-03 21:32:41 · 174 阅读 · 0 评论 -
Lotto HDU - 1342(dfs)
Lotto HDU - 1342In a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49}. A popular strategy to play Lotto - although it doesn't increase your chance of winning - is to...原创 2018-05-23 10:16:37 · 161 阅读 · 0 评论 -
Ancient Go
Ancient GoYu Zhou likes to play Go with Su Lu. From the historical research, we found that there are much difference on the rules between ancient go and modern go. Here is the rules for ancient go the...原创 2018-05-02 22:25:14 · 115 阅读 · 0 评论 -
Dungeon Master (简单广搜)三维地下城
Dungeon Master You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to m原创 2017-09-26 20:19:05 · 383 阅读 · 0 评论 -
Oil Deposits (简单深搜)积水问题
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates原创 2017-09-26 20:25:19 · 1435 阅读 · 0 评论 -
Lake Counting (简单深搜)积水问题
Lake Counting Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each...原创 2017-09-23 22:03:02 · 669 阅读 · 0 评论 -
迷宫问题 (广搜并记录路径)
迷宫问题定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。Input一个5 × 5的二维数...原创 2017-09-28 19:30:48 · 589 阅读 · 0 评论 -
Find The Multiple(深搜找倍数)
Find The Multiple Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n i原创 2017-10-10 20:39:01 · 529 阅读 · 9 评论 -
Catch That Cow (经典广搜入门题)
Catch That Cow #include#include#include#include#define MAXN 1000001using namespace std;int ret[MAXN],vis[MAXN];queue p;int bfs(int n,int k){ int cur; if(n==k) return 0; p.push原创 2017-09-26 08:48:45 · 840 阅读 · 0 评论 -
Prime Ring Problem HDU - 1016 (深搜)
Prime Ring Problem HDU - 1016 A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circle原创 2017-11-14 18:29:52 · 206 阅读 · 0 评论 -
滑雪 POJ - 1088 (记忆化搜索)
滑雪 POJ - 1088 Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 516 17 18 19 615 24 25原创 2017-11-29 20:53:57 · 530 阅读 · 0 评论 -
D - Sticks POJ - 1011 (深搜 剪枝)
D - Sticks POJ - 1011 George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how m...原创 2018-03-14 22:12:03 · 394 阅读 · 0 评论 -
A Knight's Journey (dfs)
B - A Knight's JourneyBackground The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it ...原创 2018-03-19 21:48:24 · 267 阅读 · 0 评论 -
Sudoku
SudokuYi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller. Actually, Yi Sima was playing it different. First of all, ...原创 2018-05-02 21:34:19 · 300 阅读 · 0 评论 -
A计划 HDU - 2102 (bfs)
A计划 HDU - 2102 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。 现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用...原创 2018-10-27 21:49:27 · 179 阅读 · 0 评论