![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
DFS&&BFS
deebcjrb
这个作者很懒,什么都没留下…
展开
-
bfs迷宫问题(确定起点终点类型)模板题
给定一个n*m大小的迷宫,其中*代表不可通过的墙壁,而.代表平地,S代表起点,T代表终点。移动过程中,如果当前位置是(x,y)(下标从0开始),且每次只能前往上下左右四个位置的平地。求从起点S到达终点T的最少步数。#include <iostream>#include <bitset>#include <algorithm>#include ...原创 2020-04-19 19:04:47 · 647 阅读 · 0 评论 -
求矩阵块数(BFS模板)
给出一个 m x n 的矩阵,矩阵中的元素为0或1。 称位置(x,y)与其上下左右四个位置(x,y+1)、(x,y-1)、(x+1,y)、(x-1,y)是相邻的。 如果矩阵中有若干个1是相邻的(不必两两相邻),那么称这些1构成了一个“块”。求给定的矩阵中“块”的个数。#include <iostream>#include <bitset&...原创 2020-04-19 11:31:31 · 190 阅读 · 0 评论 -
牛客题库 ACM Battle(dfs)
https://ac.nowcoder.com/acm/problem/14122原文章:https://www.cnblogs.com/GorgeousBankarian/p/10384302.html这道题有些类似下棋,赢得方法就是尽快铺满棋盘。对于这种起点、终点不确定的找最优解的搜索应该用Dfs,找到每种点滴方法的结果并筛选。因为,连通的点,相互影响,更好的方法是遍历边,边只要其中一...原创 2020-03-24 19:26:45 · 228 阅读 · 0 评论 -
模拟长草(bfs)
问题描述小明有一块空地,他将这块空地划分为 n 行 m 列的小块,每行和每列的长度都为 1。小明选了其中的一些小块空地,种上了草,其他小块仍然保持是空地。这些草长得很快,每个月,草都会向外长出一些,如果一个小块种了草,则它将向自己的上、下、左、右四小块空地扩展,这四小块空地都将变为有草的小块。请告诉小明,k 个月后空地上哪些地方有草。输入格式输入的第一行包含两个整数 n, m。接下来...原创 2020-03-19 21:55:28 · 130 阅读 · 0 评论 -
送外卖 (dfs)
原博客:https://blog.csdn.net/qq_39696016/article/details/104376916?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-taskhttps://ac.nowcoder.com/acm/problem...原创 2020-03-19 20:18:52 · 166 阅读 · 0 评论 -
(kuangbin带你飞--简单搜索)Catch That Cow(广搜)
原文章:https://blog.csdn.net/weixin_43336281/article/details/88653839Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ ...原创 2020-02-16 20:24:04 · 106 阅读 · 0 评论 -
Sudoku Killer(数独类问题)
自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视。据说,在2008北京奥运会上,会将数独列为一个单独的项目进行比赛,冠军将有可能获得的一份巨大的奖品———HDU免费七日游外加lcy亲笔签名以及同hdu acm team合影留念的机会。所以全球人民前仆后继,为了奖品日夜训练茶饭不思。当然也包括初学者linle,不过他太笨了又没有多少耐性,只能做做最...原创 2020-01-29 10:01:36 · 387 阅读 · 0 评论 -
Tempter of the Bone(DFS剪枝)
原题目:The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the...原创 2020-01-27 19:41:29 · 75 阅读 · 0 评论 -
变形课(DFS)
呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以a开头b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体.Harry已经将他所会的所有咒语都列成了一个表,他想让你帮忙计算一下他是否能完成老师的作业,将一个B(ball)变成一个M(Mouse),你知道,如果他...原创 2020-01-27 13:36:15 · 154 阅读 · 0 评论 -
牛客寒假算法基础集训营2(G 处女座与复读机 )(DP||DFS||模拟)
https://ac.nowcoder.com/acm/contest/327/G三种方法dfs实现(完全没想到这个还能dfs)#include<bits/stdc++.h>using namespace std;string s1, s2;bool flag; void dfs(int a, int b, int c) { if (c > 2)...原创 2020-01-17 00:14:36 · 112 阅读 · 0 评论 -
Play on Words (uva 10129) (DFS判断欧拉路径)
原题目:Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is ver...原创 2019-11-24 19:31:14 · 151 阅读 · 0 评论 -
欧拉回路
欧拉道路:除了起点终点外,其他点的度数应该是偶数。有向图结论:最多只能有两个点的入度不等于出度,而且必须是其中一个点的出度恰好比入度大一,(作为起点),另一个的入度比出度大一(作为终点),当然,还有一个前提条件,在忽略边的方向后,图必须是联通的。下面是程序,同时适用于欧拉道路和回路,但是若需要打印的是欧拉道路,在主程序中调用时,参数必须是道路的起点,另外,打印的顺序是逆序的,因此在...原创 2019-11-24 12:43:16 · 104 阅读 · 0 评论 -
Ordering Tasks (uva10305)(DFS判断有向环)(拓扑排序)
原题目:John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed.InputThe input will consist of sev...原创 2019-11-24 12:23:28 · 111 阅读 · 0 评论 -
判断一个图是否存在有向环(DFS判断)
解决这个问题的算法的思路是对一个节点u进行dfs,判断是否能从u回到自己这个节点,即是否存在从u到u的回路。 我们可以用一个color数组代表每个结点的状态,-1代表还没被访问,0代表正在被访问,1代表访问结束。如果一个状态为“0”(正在被访问)的结点,与他相连的结点状态也为“0”(正在被访问)的话就代表有环。#include <iostream>#include <...原创 2019-11-24 11:33:47 · 686 阅读 · 0 评论 -
Abbott's Revenge (uva816)BFS+最短路(ACM/ICPC World Final 2000 A)
原题目:The 1999 World FinalsContest included a problem based on a “dicemaze.” At the time the problem was written, the judges were unable todiscover the original source of the dice maze concept. Shortl...原创 2019-11-23 19:13:27 · 300 阅读 · 0 评论 -
Ancient Messages(uva1103)DFS
理解起来简直费死劲,脑洞大开的一题输入的是16进制数,需要转化成2进制数才能继续求解。这道题有一点很麻烦就是输入的图形可以是拉伸之后的图形。在这种情况之下,我们必须通过一些特征值来判断图形。我们发现,每个文字的“洞”的个数是不一样的,所以我们可以来数洞的个数。#include <iostream>#include <cstdio>#inc...原创 2019-11-22 22:33:15 · 115 阅读 · 0 评论 -
Oil Deposits (uva572)DFS
中文概要:输入m行n列的字符矩阵,统计字符@组成多少个八连块,如果两个字符所在的各自相邻(横竖对角),就属于同一个八连块例如:* * * * @* @@ * @* @ * * @@@@ * @@@ * * @#include <iostream>#include<algorithm>#include<string...原创 2019-11-22 21:27:17 · 80 阅读 · 0 评论