![](https://img-blog.csdnimg.cn/20190927151132530.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
搜索
BFS、DFS
zhujunhuan?
全宇宙第一帅,第一强,第一牛,第一(此处省略100000000000000000000000000000000个夸人的词语)
展开
-
特殊的质数肋骨(dfs)
闲来无事,做了一道dfs水题 特殊的质数肋骨 农民约翰的母牛总是产生最好的肋骨。你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们。 农民约翰确定他卖给买方的是真正的质数肋骨,是因为从右边开始切下肋骨,每次还剩下的肋骨上的数字都组成一个质数。 举例来说:7 3 3 1 7331 全部肋骨上的数字 7331是质数;三根肋骨 733是质数;二根肋骨 73 是质数;当然,最后一根肋骨 7 也是质数。7331 被叫做长度 4 的特殊质数。 写一个程序对给定的肋骨的数目 n,求出所有的特殊质数。1不是质数。原创 2021-11-11 18:59:57 · 279 阅读 · 0 评论 -
Lake Counting S(dfs)
题目详见洛谷P1596 很水的题目,用dfs随便切 #include<bits/stdc++.h> #define N 105 using namespace std; char a[N][N]; int n, m; bool flag[N][N]; int ans = 0; int dx[10] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[10] = {-1, 0, 1, -1, 1, -1, 0, 1}; void dfs (int x, int y) {原创 2021-11-13 08:09:48 · 363 阅读 · 0 评论 -
离开中山路(深搜or宽搜)
原题连接:离开中山路 非常的简单,我是用宽搜写的 #include<bits/stdc++.h> #define N 1005 using namespace std; int n; char a[N][N]; int dx[] = {-1, 0, 0, 1}; int dy[] = {0, -1, 1, 0}; int vis[N][N]; bool f[N][N]; queue <pair <int, int> > Q; int main() { cin >.原创 2022-01-21 07:51:51 · 458 阅读 · 0 评论 -
(ni)马的遍历(Bfs)(c++)
众所周知,BFS是一个既简单有实用的算法。有一道very经典的BFS题: luoguP1443马的遍历 #include<bits/stdc++.h> #define N 405 using namespace std; int n, m; int x, y; int a[N][N]; bool flag[N][N]; const int dx[] = {-1, -2, -2, -1, 1, 2, 2, 1}; const int dy[] = {2, 1, -1, -2, 2, 1, -1,原创 2021-12-12 18:10:37 · 826 阅读 · 0 评论