
DFS
文章平均质量分 52
哒哒哒哒哒嘭
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Tempter of the Bone
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 bone ...原创 2018-04-10 18:49:01 · 224 阅读 · 0 评论 -
Codeforces Round #500 (Div. 2) [based on EJOI] Chemical table 图论 思维 求联通快
思路 当图形呈现 1 1 1 1 0 0 1 0 0 1为有点 2为无点 时 就可以不同添加点了 1 0 0 0 1 0 1 0 0 这种情况时 1可以填入左或右 都能生成 另外 中间那个点对应的行或列 也就相当于 每个点的(x,y)看成x和y相连 (x1,y1)(x2,y2) ...原创 2018-08-14 17:18:58 · 233 阅读 · 0 评论 -
Undraw the Trees UVA - 10562 DFS实现
思路:判欧拉回路 一个是对应无向图连通 用DFS 继续判 入度 不等于出度的点 不符合2个以内 2个其中一个入度大于出度1,另一个出度大于入度1 #include<bits/stdc++.h> using namespace std; char s[1005]; int vis[26]; int mp[27][27]; int indgree[26],outdgree[26];...原创 2018-07-15 17:05:53 · 258 阅读 · 0 评论 -
Ordering Tasks UVA - 10305 DFS拓扑排序
理解:一道DFS的水题,平常写的有显示的入度出度表示,而这个的刘汝佳的代码没有用显示表示,而是用DFS形成类似树的结构,不同枝的顺序可以任意 而在toposort里面没有用到的点再进行DFS则是把没有用到的点作为新树的根,其中,把当前结点加入拓扑排序的首部(线性序列的当前第一个位置,随着排序的进行,这个位置会不断前移)很关键 其实这种方法就是把入度出度隐藏起来了#include<bits/...原创 2018-07-15 15:36:17 · 193 阅读 · 0 评论 -
Golygons UVA - 225 dfs回溯 坐标平移
一道很简单的题目,但是写的时候莫名奇妙小错误不断很坑爹 用sum前缀和 相减表示最小步数剪枝 同时 可以自交的意思是路线上可以相交,但是不可以停在同一个点 这有点坑爹啊 因为有负坐标 把负的全部映射成正的 大于 (1+n)*n/2的一半的肯定返回不了了,这种障碍点可以直接去掉不用管 #include<bits/stdc++.h> using namespace std; con...原创 2018-07-19 20:26:05 · 270 阅读 · 0 评论 -
Firetruck UVA - 208 双向DFS
回溯搜索题 不能裸搜,因为有终点和起点不连通的情况 可以从终点DFS一次找出联通标记出后再用DFS回溯出来 也可以用并查集( 但是写并查集好累啊!) 还有输出格式有点坑,1前面是没空格的 #include<bits/stdc++.h> using namespace std; int n; vector<int>a1[300]; int vis[25]; int l...原创 2018-07-19 17:40:46 · 328 阅读 · 0 评论 -
Krypton Factor UVA - 129 回溯
往后面加字符 每加一位需要判断包括最后一位的偶数位数字串会不会相等 就像八皇后那样只需要判断判断包括后缀字串会不会重复不需要判断前面的,因为前面的已经在上一层解答树里面判断过了 #include<bits/stdc++.h> using namespace std; int n,l; int s[200]; int cnt=0; int dfs(int cur){ if(cnt+...原创 2018-07-19 16:09:19 · 255 阅读 · 0 评论 -
Prime Ring Problem UVA - 524回溯
回溯 要注意第一位一定是1 给题目要用的素数打个表 #include<bits/stdc++.h> using namespace std; int n; typedef long long ll; int kase=1; int vis[20]; int ans[20]; bool isp[45]; void dabiao(){ isp[1]=1; for...原创 2018-07-19 15:57:06 · 216 阅读 · 0 评论 -
Mobile Computing UVA - 1354
思路:这题是回溯枚举二叉树找最大值 有意思的是他是从叶开始构造,2个合成一个然后把新的加入子叶表里面 用index动态表示下表 vis[]表示存在与否 其中宽度的计算是难点 要考虑右边的子树的左儿子可能超过左边的子树的右儿子的类似情况,同时需要用数学推导出的公式计算新产生的合成节点的左右长度 由题意不用考虑精度,不然就坑爹了 #include<bits/stdc++.h> u...原创 2018-07-17 18:24:47 · 285 阅读 · 0 评论 -
Self-Assembly UVA - 1572 拓扑排序
思路:书上的思路把正方形看成边,因为可以折叠跟翻转,所以不用考虑拼完后的形状 能接上就OK其中连接时 应该把所有的前面的符号翻转如A+A+ 代表A-可以和A+相连 A-B+代表A+可以和B+相连 最后构成一个有向图拓扑看有没有环 #include<bits/stdc++.h> using namespace std; int mp[52][52];//前26为正 后26为负 vo...原创 2018-07-16 10:52:10 · 217 阅读 · 0 评论 -
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 is not greater than 200 and there...原创 2018-04-10 19:21:27 · 149 阅读 · 0 评论 -
哈密顿绕行世界问题
一个规则的实心十二面体,它的 20个顶点标出世界著名的20个城市,你从一个城市出发经过每个城市刚好一次后回到出发的城市。 Input前20行的第i行有3个数,表示与第i个城市相邻的3个城市.第20行以后每行有1个数m,m<=20,m>=1.m=0退出. Output输出从第m个城市出发经过每个城市1次又回到m的所有路线,如有多条路线,按字典序输出,每行1条路线.每行首先输出是第几条路线...原创 2018-04-10 19:18:55 · 175 阅读 · 0 评论 -
poj3009Curling
On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is mark...原创 2018-04-10 18:56:41 · 154 阅读 · 0 评论 -
牛客练习赛24 凤凰 dfs
思路:因为和根节点相连的边每秒只能过一个 所以找到根的子节点中 子节点最多的那个根子节点 就是答案了 #include<bits/stdc++.h> using namespace std; vector<int>G[1000010]; int dfs(int x,int pre){ int cnt=1; for(auto&v:G[x]){ if(v!=...原创 2018-08-11 13:05:50 · 306 阅读 · 0 评论