DFS/BFS
文章平均质量分 80
chAngE_AC
这个作者很懒,什么都没留下…
展开
-
poj-3009 Curling 2.0-DFS
题干很长这里就不复制了,题意的话估计看图就能懂个差不多,这里简单说一下,一个球在2为起点的位置要到达终点3,途中不碰到墙壁球的移动是不会停止的,并且在触碰墙壁停止后,被碰的墙壁会消失。最后得出到达3需要的最少步数。 思路:还是平常的DFS,不过需要多加一点东西就是了,比如点的移动时用一个循环使其向一个方向一直移动到碰到墙或走出边界。该题不需要vis标记数组,因为存在重复走点的情况原创 2015-08-18 14:25:48 · 412 阅读 · 0 评论 -
poj-1129 Channel Allocation
题意:广播电台分布在一个很大的地方,每个广播电台为了受到更强的信号会使用一个中继器,而每个相邻的广播电台之间如果使用相同的中继器会干扰信号。问最少需要多少个中继器可以让所有广播电台使用并不相互影响。 思路:该题可以模拟成涂色问题,每个相邻的区域不能涂相同的颜色。这也就会想到著名的四色原理。根据四色原理对每个区域只需要枚举4种情况即可。每个点只枚举一次,DFS里其实并没有回溯的过原创 2015-08-21 15:01:08 · 327 阅读 · 0 评论 -
poj-1416 Shredding Company DFS
题意:有一个碎纸机,给你一个最多有6位数的纸片,需要让你将纸片切开,使得切开的纸片的数值和最接近或等于target值。输入target和纸片,输出最接近target的值和纸片的切法。特殊规则:如果纸片的值和target相等,那么不用切开。如果所有情况下都不存在小于target的切法,那么输出error。如果最终的答案有多种,那么输出rejected。 思路:DFS搜索所有切开纸片原创 2015-08-20 14:05:23 · 556 阅读 · 0 评论 -
poj-2531 Network Saboteur DFS
题意:有n个点,把这些点分别放到两个集合里,在两个集合的每个点之间都会有权值,求最大的两集合间权值和。如果用图论解释的话,就是求两个完全图之间最大割边和。 思路:DFS枚举所有集合分配的情况。累加两集合间边的权值。找出最大和。#include #include #include #include #include #define INF 0x3f3f3f3f#de原创 2015-08-19 15:46:24 · 442 阅读 · 0 评论 -
poj-3414 Pots BFS
题意:有1,2两个杯子,你需要对杯子进行操作,操作包括fill填满,pour(1,2)将1倒入2种或反过来,drop倒出所有水。求出使两个杯子中出现指定量C的水需要多少步操作,并且输出操作步骤 思路:BFS对六种操作进行搜索,和以往不同的需要在结构体里加一个数组来记录操作(本人用1-6编号进行记录)。输出时对应记录输出步骤即可。#include #include #inc原创 2015-08-19 13:43:44 · 460 阅读 · 0 评论 -
poj-3126 Prime Path
题目描述其实就是篇小故事,不多解释直接说明题意。题意要求给两个4位的素数,求出将前一个素数转化为后一个素数需要的步数。一次只能改变一位数字,且保证每次改变得到的数都是素数 思路:用BFS暴搜,每次改变一位数如果是素数就进入队列,但是暴搜的前提要把1w以内的素数筛出来。为了方便对每一位上的数的操作,本人用的字符串来储存4位数字。#include #include #include原创 2015-08-19 09:16:24 · 489 阅读 · 0 评论 -
poj-1426 Find The Multiple
DescriptionGiven 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原创 2015-08-18 19:44:33 · 359 阅读 · 0 评论 -
poj-2251 Dungeon Master BFS
DescriptionYou are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit原创 2015-08-18 16:54:45 · 647 阅读 · 0 评论 -
poj-1321 棋盘问题 DFS
汉语题,不解释题意,该题关键是要找到一个枚举的方法,刚开始搜索的思路不是很好找。我也是参考了其他网友的思路,写了这个代码,不是很好解释,直接看把。#include #include #include #include #include #include #define INF 0x3f3f3f3fusing namespace std;int n,k,ans;char m原创 2015-08-18 16:53:18 · 499 阅读 · 0 评论 -
poj-3026 Borg Maze BFS+最小生成树
DescriptionThe Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. The Borg collective is the term used to describe the group consciousness of the Borg ci原创 2015-07-31 14:03:41 · 584 阅读 · 0 评论 -
poj-3083 Children of the Candy Corn-DFS+BFS
DescriptionThe cornfield maze is a popular Halloween treat. Visitors are shown the entrance and must wander through the maze facing zombies, chainsaw-wielding psychopaths, hippies, and other terrors原创 2015-08-01 14:53:51 · 380 阅读 · 0 评论 -
poj-2049 Finding Nemo-BFS
DescriptionNemo is a naughty boy. One day he went into the deep sea all by himself. Unfortunately, he became lost and couldn't find his way home. Therefore, he sent a signal to his father, Marlin, t原创 2015-08-06 08:04:49 · 333 阅读 · 0 评论 -
poj-2676 Sudoku
题意:数独,一种数学游戏。规则:空白处填入数字,使数独的每一行,每一列,每个宫格中没有重复数字。 思路:该题DFS暴搜就能过,数据比较水,真正厉害的数独题是3074(本人目前无力AC)。#include #include #include #include #include #include #define INF 0x3f3f3f3f#define mod 10原创 2015-08-20 14:31:22 · 500 阅读 · 0 评论