
搜索
幽殇默
他时若遂凌云志,敢笑黄巢不丈夫。
展开
-
B. Dreamoon and WiFi【1300 / 简单爆搜】
https://codeforces.com/problemset/problem/476/B#include<bits/stdc++.h>using namespace std;string a,b;int cnt1,cnt2,cnt11,cnt22,n;int sum,ans;void dfs(int a,int b,int index){ if(index==n) { if(a==cnt1&&b==cnt2) ans++; sum++; re.原创 2021-11-05 22:35:24 · 131 阅读 · 0 评论 -
B. Badge【1000 / dfs 】
https://codeforces.com/problemset/problem/1020/B#include<bits/stdc++.h>using namespace std;const int N=1e3+10;int h[N],e[N],ne[N],idx; bool st[N];void add(int a,int b) {e[idx]=b,ne[idx]=h[a],h[a]=idx++;}int dfs(int u){ st[u]=1; for(int i=h.原创 2021-10-23 09:06:23 · 127 阅读 · 0 评论 -
1113. 红与黑【连通块】
https://www.acwing.com/problem/content/1115/#include<bits/stdc++.h>using namespace std;const int N=25;char s[N][N];int n,m,st[N][N],startx,starty,cnt;int dx[4]={-1,0,0,1};int dy[4]={0,-1,1,0};void dfs(int x,int y){ st[x][y]=1; for(i.原创 2021-10-18 22:00:11 · 105 阅读 · 0 评论 -
1112. 迷宫【dfs板子题】
https://www.acwing.com/problem/content/1114/#include<bits/stdc++.h>using namespace std;int t,n,startx,starty,endx,endy;int st[101][101];int dx[4]={-1,0,0,1};int dy[4]={0,-1,1,0};bool flag;string s[110];void dfs(int x,int y){ st[x][y]=1.原创 2021-10-18 21:46:48 · 160 阅读 · 0 评论 -
190. 字串变换【双向广搜】
https://www.acwing.com/problem/content/description/192/普通的搜索双向广搜#include<bits/stdc++.h>using namespace std;const int N=10;string a[N],b[N],A,B;int n;int change(queue<string> &q,unordered_map<string,int>&hush1,unordered_.原创 2021-10-18 15:19:22 · 85 阅读 · 0 评论 -
175. 电路维修【双端队列广搜】
https://www.acwing.com/problem/content/description/177/双端队列广搜的本质,其实还是基于Dijkstra(),主要用于解决边长只有0,1的情况。边长为0添加到对头,边长为1添加到队尾。#include<bits/stdc++.h>using namespace std;const int N=510;string s[N];int t,n,m;int dx[4]={-1,-1,1,1};//所到的四个点的坐标int dy.原创 2021-10-18 13:59:27 · 147 阅读 · 0 评论 -
173. 矩阵距离【多源bfs】
https://www.acwing.com/problem/content/description/175/#include<bits/stdc++.h>using namespace std;const int N=1e3+10;string a[N];int dist[N][N],n,m;int dx[4]={-1,0,0,1};int dy[4]={0,-1,1,0};void bfs(){ memset(dist,-1,sizeof dist); q.原创 2021-10-18 10:33:38 · 86 阅读 · 0 评论 -
1100. 抓住那头牛【最短路的特殊移动】
https://www.acwing.com/problem/content/1102/#include<bits/stdc++.h>using namespace std;const int N=1e5+10;int startx,endx;int d[N],st[N];int bfs(){ queue<int>q; q.push(startx); st[startx]=1; while(q.size()) { int.原创 2021-10-18 10:19:50 · 102 阅读 · 0 评论 -
188. 武士风度的牛【模板bfs求最小步数】
https://www.acwing.com/problem/content/description/190/#include<bits/stdc++.h>using namespace std;const int N=210;char a[N][N];int st[N][N],n,m;int startx,starty,endx,endy;struct node{int x,y,step;};int dx[10]={-2,-2,-1,1,-1,1,2,2};int dy[1.原创 2021-10-18 10:10:58 · 106 阅读 · 0 评论 -
1076. 迷宫问题【存路径的bfs】
https://www.acwing.com/problem/content/description/1078/存路径的时候存的是这个点从哪里来的,即上一个点。#include<bits/stdc++.h>using namespace std;const int N=1010;int a[N][N],n,st[N][N];map<pair<int,int>,pair<int,int>>mp;struct node {int x,y;}temp.原创 2021-10-17 23:26:57 · 113 阅读 · 0 评论 -
1106. 山峰和山谷【变种的搜索 求连通块】
https://www.acwing.com/problem/content/description/1108/本质上是一个特别裸的求联通块的问题,但是有一点的变种,就是我们要判断周围的数是不是都比它大,周围的数是不是都比它小,所以可以用两个bool变量判断。如果没有一个比它高的则必为山峰。如果没有一个比它第低的则必为山谷。#include<bits/stdc++.h>using namespace std;const int N=1010;int a[N][N],n,cnt1.原创 2021-10-17 16:48:34 · 157 阅读 · 0 评论 -
1098. 城堡问题【搜索 求连通块】
https://www.acwing.com/problem/content/description/1100/本质就是一个求连通块的问题,但是因为墙的限制有的不可以走。你会发现墙分别为 1 2 4 8 故可以用位运算的思想来判断可不可以走即可。#include<bits/stdc++.h>using namespace std;const int N=105;int n,m,a[N][N],st[N][N];int ans,res,cnt;int dx[4]={0,-1,0,.原创 2021-10-16 18:56:36 · 118 阅读 · 0 评论 -
1097. 池塘计数【Flood Fill 搜索】
https://www.acwing.com/problem/content/1099/很裸的一个求连通块的问题用bfs()写 缺点: 对于本题代码有点长#pragma GCC optimize(2)#include<bits/stdc++.h>using namespace std;const int N=1e3+10;char a[N][N];int st[N][N],n,m,ans;int dx[8]={-1,-1,-1,0,0,1,1,1};int dy[8]={.原创 2021-10-16 18:35:44 · 106 阅读 · 0 评论 -
【2021.5.16】3481. 阶乘的和
题目地址通过题目的数据范围可以分析出,其最大值到 9!。题目给的意思就是可不可用各个的阶乘和来凑出n,且每一个阶乘只可以用一次。爆搜方法:#include<cstdio>#include<iostream>#include<algorithm>#include<vector>#include<cstring>using namespace std;int a[15]={1,1,2,6,24,120,720,5040,40320.原创 2021-06-07 16:00:45 · 169 阅读 · 0 评论 -
【2021.5.13】3502. 不同路径数
题目地址#include<cstdio>#include<iostream>#include<vector>#include<map>#include<set>using namespace std;const int N=10;int n,m,k;int a[N][N];int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};set<int> st;void dfs(int x,.原创 2021-06-05 17:59:03 · 117 阅读 · 0 评论 -
八皇后 【简单 / 全排列】
https://www.nowcoder.com/practice/fbf428ecb0574236a2a0295e1fa854cb?tpId=40&tqId=21417&rp=1&ru=%2Fta%2Fkaoyan&qru=%2Fta%2Fkaoyan%2Fquestion-ranking&tab=answerKey案例是真的坑,输入只有一次,然后输出结果。案例给的输入 n,再输入n纯属在胡扯。#include<cstdio>#include&l.原创 2021-04-09 22:06:57 · 117 阅读 · 0 评论 -
【1312】 Red and Black 【简单 / dfs】
http://acm.hdu.edu.cn/showproblem.php?pid=1312#include<cstdio>#include<iostream>#include<cstring>using namespace std;int n,m;char a[1005][1005];bool vis[1005][1005];int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};int startx,starty;i.原创 2021-05-08 19:52:19 · 98 阅读 · 0 评论 -
【1043】Eight 【没做出来】
http://acm.hdu.edu.cn/showproblem.php?pid=1043没做出来,用了好几种我会的方法都没做出来。可能自己太菜了,目前自己的水平有待提高。我的方法一: map去重 MLE#include<cstdio>#include<iostream>#include<map>#include<queue>#include<algorithm>using namespace std;char a[4.原创 2021-05-07 20:13:40 · 114 阅读 · 0 评论 -
P1434 [SHOI2002]滑雪 【记忆化搜索】
https://www.luogu.com.cn/problem/P1434朴素算法:会TLE一个点#include<cstdio>#include<iostream>#include<cstring>using namespace std;const int N=110;int f[N][N],a[N][N],n,m;bool vis[N][N];int ans;int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};.原创 2021-05-18 22:12:00 · 108 阅读 · 0 评论 -
24. 机器人的运动范围 【dfs】
https://www.acwing.com/problem/content/description/22/int ans=0;bool vis[110][110];int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};bool check(int x,int y,int k){ int a=0,b=0; while(x) a+=x%10,x/=10; while(y) b+=y%10,y/=10; int sum=a+b; if(sum<=k) .原创 2021-05-17 22:57:32 · 161 阅读 · 0 评论 -
165. 小猫爬山 【有意思的 / bfs】
https://www.acwing.com/problem/content/description/167/思路: 枚举当前的每一个猫放在哪一个缆车里,当猫放完后,看用了多少缆车。#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int N=20;int cat[N],sum[N],w,n,ans=9999;void dfs(int inde.原创 2021-05-17 19:05:22 · 215 阅读 · 0 评论 -
HDU【2044】一只小蜜蜂 【简单记忆化搜索】
http://acm.hdu.edu.cn/showproblem.php?pid=2044由图可以知道,当前位置的路线数等于它从上面来的路线数加上它从左边来的路线数。规律不难得出就是一个简单的斐波那契数列。递推:#include<cstdio>#include<iostream>#include<algorithm>using namespace std;long long int s[55];int main(void){ s[0]=1;.原创 2021-05-17 18:50:31 · 140 阅读 · 0 评论 -
火星人 【全排列】
https://ac.nowcoder.com/acm/problem/16661#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int main(void){ int n,m; cin>>n>>m; int a[100005]; for(int i=0;i<n;i++) cin>>a[i]; while(m--.原创 2021-05-14 11:23:35 · 140 阅读 · 0 评论 -
扫雷游戏 【dfs】
https://ac.nowcoder.com/acm/problem/16491#include<cstdio>#include<iostream>using namespace std;const int N=105;char a[N][N];int n,m;int dx[8]={-1,-1,-1,0,0,1,1,1};int dy[8]={-1,0,1,-1,1,-1,0,1};int dfs(int x,int y){ int ans=0; for(.原创 2021-05-14 11:12:30 · 147 阅读 · 0 评论 -
【P1379】 八数码难题
https://www.luogu.com.cn/problem/P1379#include<cstdio>#include<iostream>#include<map>#include<queue>#include<algorithm>using namespace std;char a[4][4];int dx[4]={-1,0,1,0};int dy[4]={0,-1,0,1};string ans="123804765.原创 2021-05-07 15:48:38 · 186 阅读 · 0 评论 -
【洛谷算法1-7】【搜索DFS】习题解析
目录[USACO1.5]八皇后 Checker Challenge 【经典】P1135 奇怪的电梯【经典】P1036 [NOIP2002 普及组] 选数 【经典 n中选k】P1605 迷宫 【经典】P1101 单词方阵 【有意思】P2404 自然数的拆分问题 【有点意思 / 经典】P1596 [USACO10OCT]Lake Counting S 【经典】P1162 填涂颜色 【思维秒】[USACO1.5]八皇后 Checker Challenge 【经典】https://www.luogu.com.原创 2021-04-17 22:48:05 · 882 阅读 · 1 评论