![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
搜索
文章平均质量分 65
青龙指引你
也并非所有的流浪者都迷失了自我
展开
-
DFS——A:N皇后问题 解题报告
N皇后问题Description在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。你的任务是,对于给定的N,求出有多少种合法的放置方法。 Input共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。原创 2016-07-22 17:26:34 · 1009 阅读 · 0 评论 -
CSU 1960:单源最大权路径 (DFS)
有一棵由N个结点构成的树,每一条边上都有其对应的权值。现在给定起点,求从该点出发的一条路径(至少有一条边)使得这条路径上的权值之和最大,并输出这个最大值。原创 2017-07-28 16:48:47 · 402 阅读 · 0 评论 -
CSU 1224: ACM小组的古怪象棋(BFS)
ACM小组的Samsara和Staginner对中国象棋特别感兴趣,尤其对马(可能是因为这个棋子的走法比较多吧)的使用进行深入研究。今天他们又在 构思一个古怪的棋局:假如Samsara只有一个马了,而Staginner又只剩下一个将,两个棋子都在棋盘的一边,马不能出这一半棋盘的范围,另外这 一半棋盘的大小很奇特(n行m列)。Samsara想知道他的马最少需要跳几次才能吃掉Staginner的将(我们假定其不会移动)。原创 2017-07-31 20:44:25 · 405 阅读 · 0 评论 -
HDU 1016:Prime Ring Problem(基础DFS)
Prime Ring ProblemTime limit:2000 ms Memory limit:65536 kB OS:Linux Problem DescriptionA ring is compose of n circles as shown in diagram. Put natural number 1, 2, …, n into each circle separately, an原创 2017-09-20 20:04:00 · 333 阅读 · 0 评论 -
hihoCoder 1054:滑动解锁(DFS)
滑动解锁Time limit:2000 ms Memory limit:256MB Problem Description滑动解锁是智能手机一项常用的功能。你需要在3x3的点阵上,从任意一个点开始,反复移动到一个尚未经过的”相邻”的点。这些划过的点所组成的有向折线,如果与预设的折线在图案、方向上都一致,那么手机将解锁。两个点相邻当且仅当以这两个点为端点的线段上不存在尚未经过的点。此外,这条折线还需原创 2017-10-11 22:32:41 · 440 阅读 · 0 评论 -
Wannafly挑战赛1:A-Treepath(DFS或BFS)
TreepathTime limit:1000ms Memory limit:32768K Problem Description给定一棵n个点的树,问其中有多少条长度为偶数的路径。路径的长度为经过的边的条数。x到y与y到x被视为同一条路径。路径的起点与终点不能相同。Input第一行一个数n表示点的个数; 接下来n-1行,每行两个整数x,y表示边; 保证输入数据形成一棵树; 1<=n<=10原创 2017-10-23 19:17:41 · 402 阅读 · 0 评论 -
PAT(Advanced Level) 1003. Emergency(25) 最短路 + DFS
题目链接EmergencyTime limit:1 seconds Memory limit:256 megabytes Problem DescriptionIAs an emergency rescue team leader of a city, you are given a special map of your country. The map shows...原创 2018-03-07 23:31:18 · 257 阅读 · 0 评论 -
PAT (Advanced Level) 1004. Counting Leaves (30) BFS
题目链接Counting LeavesTime limit:1 seconds Memory limit:256 megabytes Problem DescriptionA family hierarchy is usually presented by a pedigree tree. Your job is to count those family members w...原创 2018-03-09 15:37:48 · 229 阅读 · 0 评论 -
PAT (Advanced Level) 1013. Battle Over Cities (25) DFS求连通分量
题目链接1013. Battle Over Cities (25)Time limit:400 ms Memory limit:65536 kBProblem DescrpitionIt is vitally important to have all the cities connected by highways in a war. If a city is o...原创 2018-04-25 19:11:04 · 199 阅读 · 0 评论 -
CF#479 D:Divide by three, multiply by two(DFS)
题目链接Divide by three, multiply by two题意有一个数x,经过一下两种操作×2÷3结果记录在黑板上,但顺序是乱的,现在要我们求正确的顺序解题思路直接搜索,搜到结果回溯时记录就可以了Code#include "cstdio"#include "iostream"#include "cstring"#includ...原创 2018-05-07 00:19:26 · 1050 阅读 · 0 评论 -
CF#482:C Kuro and Walking Route(DFS)
题目链接Kuro and Walking Route题意无向图,n个点,n-1条边,每两个点都可以到达,但是从依次经过u,v两点的道路不能走,问有多少个x->y可以到达解题思路根据题意可知这是一个最小生成树,那么u到v只有一条道路可走 结果用总数减去A的数量×B的数量就可以了 确定数量用DFSCode#include "bits/stdc++.h"...原创 2018-05-15 21:05:29 · 726 阅读 · 0 评论 -
HDU - 2553:N皇后问题(经典DFS)
在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 你的任务是,对于给定的N,求出有多少种合法的放置方法。原创 2017-07-28 16:35:53 · 607 阅读 · 0 评论 -
CSU 1815:Enterprising Escape(BFS+优先队列)
The Enterprise is surrounded by Klingons! Find the escape route that has the quickest exit time, and print that time. Input is a rectangular grid; each grid square either has the Enterprise or some class原创 2017-08-02 17:35:34 · 359 阅读 · 0 评论 -
HDU 1548:A strange lift(BFS)
There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and down.When you at floor i,if you press the b原创 2017-08-02 17:19:26 · 280 阅读 · 0 评论 -
hdu 3786 找出直系亲属 (DFS)
找出直系亲属Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1678 Accepted Submission(s): 680Problem Description如果A,B是C的父母亲,则A,B是C的p原创 2017-03-19 18:30:15 · 465 阅读 · 0 评论 -
ZCMU 1803 2n皇后问题 (DFS)
给定一个n*n的棋盘,棋盘中有一些位置不能放皇后。现在要向棋盘中放入n个黑皇后和n个白皇后,使任意的两个黑皇后都不在同一行、同一列或同一条对角线上,任意的两个白皇后都不在同一行、同一列或同一条对角线上。问总共有多少种放法?n小于等于8。原创 2017-07-04 13:59:05 · 361 阅读 · 0 评论 -
CSU 1973:给自己出题的小X(DFS或DP)
小X学习了dfs,为了练习搜索,开始给自己出题玩。 玩着玩着,一会把自己难住了,一会又被自己难倒了,真是有趣诶! 小X出的题: 现在有N个不同的正整数,求它们可以组成多少个这样的集合,满足:集合内的元素数量S>1集合内任意两个数的差的绝对值都大于集合内的元原创 2017-07-29 20:38:34 · 496 阅读 · 3 评论 -
CSU - 1600:Twenty-four point(DFS)
Given four numbers, can you get twenty-four through the addition, subtraction, multiplication, and division? Each number can be used only once.原创 2017-07-28 20:38:36 · 293 阅读 · 0 评论 -
HDU 1312:Red and Black(BFS)
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on原创 2017-07-31 17:41:15 · 401 阅读 · 0 评论 -
HDU 1241:Oil Deposits(BFS)
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land int原创 2017-07-31 20:14:39 · 239 阅读 · 0 评论 -
HDU 1242:Rescue(BFS+优先队列)
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison.原创 2017-07-31 20:38:57 · 338 阅读 · 0 评论 -
CodeForces 616C:The Labyrinth(BFS)
You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cell原创 2017-07-31 20:46:03 · 638 阅读 · 0 评论 -
CSU 1726:你经历过绝望吗?两次! (BFS+优先队列)
4月16日,日本熊本地区强震后,受灾严重的阿苏市一养猪场倒塌,幸运的是,猪圈里很多头猪依然坚强存活。当地15名消防员耗时一天解救围困的“猪坚强”。不过与在废墟中靠吃木炭饮雨水存活36天的中国汶川“猪坚强”相比,熊本的猪可没那么幸运,因它们最终还是没能逃过被送往屠宰场的命运。原创 2017-08-01 08:32:13 · 730 阅读 · 0 评论 -
POJ 1915:Knight Moves(BFS)
Background Mr Somurolov, fabulous chess-gamer indeed, asserts that no one else but him can move knights from one position to another so fast. Can you beat him? The Problem Your task is to write a program原创 2017-07-31 17:48:18 · 1008 阅读 · 0 评论 -
PAT (Advanced Level)1020 Tree Traversals (25) 树的遍历
题目链接1020 Tree Traversals (25)题意前序遍历:Preorder Traversal中序遍历:Inorder Traversal后序遍历:PostorderTraversal层次遍历:level order traversal已知中序和后序,求层次遍历解题思路由中序和后序来建树,因为中序的最后一个必定是根节点,只要再该根节点左右继续构建...原创 2018-06-16 16:02:29 · 247 阅读 · 0 评论