一二三四五 上山打老虎

随笔分类 -  dfs

搜索
摘要:链接:https://leetcode-cn.com/problems/find-eventual-safe-states/ 题意:如果在环上或者能到达再环上的点则不满足题意,否则输出。 方法一:DFS+染色 判环: 0:未访问过 1:在环上或者在递归的过程中 2:不在环上也不到环 代码: clas 阅读全文
posted @ 2021-08-05 21:43 abestxun 阅读(40) 评论(0) 推荐(0) 编辑
摘要:链接:https://pintia.cn/problem-sets/994805046380707840/problems/1336215880692482060 思路:dfs一下每个点到终点的条数,并记录走过的点:如果存在走过的点到达不了终点(也就是线路条数为0)则不满足条件。 代码: #incl 阅读全文
posted @ 2021-04-23 19:00 abestxun 阅读(197) 评论(0) 推荐(0) 编辑
摘要:链接:https://www.acwing.com/problem/content/1115/ 代码: bfs: #include<iostream> #include<algorithm> #include<queue> using namespace std; char s[25][25]; i 阅读全文
posted @ 2021-04-15 10:49 abestxun 阅读(57) 评论(0) 推荐(0) 编辑
摘要:链接:https://www.acwing.com/problem/content/1103/ 代码: #include<bits/stdc++.h> using namespace std; using PII=pair<int,int>; int dx[]={0,-1,0,1}; int dy[ 阅读全文
posted @ 2021-04-15 10:44 abestxun 阅读(64) 评论(0) 推荐(0) 编辑
摘要:链接:https://www.acwing.com/problem/content/1211/ 备注:观看acwing视频课后总结,思路/总结有所借鉴 思路:num=a+bc,则我们可以枚举任意两个变量,为了防止精度损失,化简除法为乘法=》 \(b=c\times(num- 阅读全文
posted @ 2021-04-07 16:55 abestxun 阅读(65) 评论(0) 推荐(0) 编辑
摘要:链接:http://118.190.20.162/view.page?gpid=T1 思路:要求计算能由S到达的点,但是不能到达T的点的数目。从S点开始dfs一下后标记,然后从T逆向遍历标记。或者从s点开始bfs遍历一遍后把访问的点加到队列中,然后计算队列中能到达T点的数目。 代码: #includ 阅读全文
posted @ 2021-04-06 16:47 abestxun 阅读(91) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805456881434624 题意:给定一个n和一个k,然后给定n个a b num, a为长度为3的大写字母构成的字符串,b也是,num为a和b的通话时间,给定的图 阅读全文
posted @ 2021-03-01 20:24 abestxun 阅读(57) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://ac.nowcoder.com/acm/problem/106350 题意:有个4x4的棋盘,棋盘上黑子翻过来是白子,白子翻过来是黑子,每翻一个子,其上,下,左,右共五个子都会对应翻过来,给出当前状况,问至少翻几个子会使整个棋盘都是一个颜色。 思路1:直接dfs深搜 O(2 阅读全文
posted @ 2021-01-19 18:36 abestxun 阅读(36) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示