dfs bfs
whiskey_wei
这个作者很懒,什么都没留下…
展开
-
hdu4707 hdu1241-dfs&bfs
hdu4707 hdu1241-dfs&bfs原创 2017-04-08 11:51:24 · 263 阅读 · 0 评论 -
迷宫问题进阶
https://www.nowcoder.net/acm/contest/68/B 是一个关于二维迷宫的题目。我们要从迷宫的起点 'S' 走到终点 'E',每一步我们只能选择上下左右四个方向中的一个前进一格。 'W' 代表墙壁,是不能进入的位置,除了墙壁以外的地方都可以走。迷宫内的 'D' 代表一道上锁的门,只有在持有钥匙的时候才能进入。而 'K' 则代表了钥匙,只要进入这一格,就会自动地拿...原创 2018-02-10 12:51:14 · 468 阅读 · 0 评论 -
迷宫问题bfs
问题并不复杂,用bfs搜索,从起点到终点即为最短路程。 但是判断条件写错了,找了半天错误,ma[x][y]!='#',开始写的是ma[x][y]=='-',如果按照刚开始的写法,是不能搜索到'E'终点的; #include #include #include #include using namespace std; struct node { int x,y,step; }; int原创 2017-07-21 16:26:01 · 308 阅读 · 0 评论 -
poj1979-dfs
dfs的入门题,水~。。。(注意判断条件就行了) #include #include #include using namespace std; char ma[25][25]; bool vis[25][25]; int dx[4]={-1,0,1,0}; int dy[4]={0,1,0,-1}; int m,n; int cnt; void dfs(int x,int y) { i原创 2017-07-19 20:55:08 · 193 阅读 · 0 评论 -
poj2531(dfs)Network Saboteur
poj2531看到这个题分类在dfs里,但是完全没有思路。。。看了下别人的博客。。先将所有点放在一个集合里,然后取出一个点放在另一个集合里,对于在同一个集合里的点,减去他们两个之间的权值,对于不在一个集合里的点,加上他们之间的权值。#include<cstdio> #include<iostream> #include<cstring> using namesp...原创 2017-07-22 17:33:26 · 290 阅读 · 0 评论 -
bfs poj3126 Prime Path
poj3126开始想了半天没思路,后来百度了下。。。用bfs对每一位数进行讨论。要注意的是,千位数不能为零(错了好多次)也可以用数组存各个位数,利用循环,代码会短很多。 #include<cstdio> #include<iostream> #include<queue> #include<cmath> #include<cstring>...原创 2017-07-22 16:56:44 · 206 阅读 · 0 评论 -
通畅工程
水题,dfs,并查集都可以做,习惯于dfs #include #include #include using namespace std; int n,m; bool vis[1005][1005]; bool v[1005]; void dfs(int x) { v[x]=1; //cout for(int i=1;i if(vis[x][i]&&!v[原创 2017-07-20 12:34:07 · 229 阅读 · 0 评论 -
dfs-hdu2782
题目:hdu2782 题意: 选择任意一个点作为起始点能否遍历到所有的点。 开始时选择一个方向,如果没有碰到障碍物,边界就一直按照这个方向走下去。 如果有多个起点选择行列数最小的作为答案,同一个起点如果有多条路线则按照字典中字母顺序排在前面的作为答案 #include #include #include using namespace std; bool vis[630][630],ma原创 2017-04-22 21:09:29 · 287 阅读 · 0 评论 -
并查集_hdu1213
How Many Tables http://acm.hdu.edu.cn/showproblem.php?pid=1213 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how man原创 2017-04-12 18:59:47 · 3009 阅读 · 1 评论 -
poj2488
原题:http://poj.org/problem?id=2488 题意是选择从任意位置开始以象棋中马的走法遍历,如能够遍历到所有的点则,输出路径; 理解: (1)按照dfs进行深搜,如果按照跳马的规则无路可走而棋盘还没有全部遍历完时,则要撤销这一步,让这一步重新标记为未被访问的状态; (2)当有多条路径可以遍历完时,按照字典的顺序输出字母最小的那条路,这时应该考虑到A1这个点,无论怎样的转载 2017-04-17 19:53:24 · 427 阅读 · 0 评论 -
Educational Codeforces Round 42 (Rated for Div. 2)
/* C 题意:给你一个数,问最少删除几个数字使得剩下的数 是一个正整数的平方数(所以0是不符合题意的,当时被 这个坑了); 思路:直接dfs爆搜枚举了,找到最大的那个平方数,判断 位数就可以了; */ #include<bits/stdc++.h> using namespace std; struct node { long long x; int b[15];...原创 2018-04-11 17:26:18 · 111 阅读 · 0 评论