![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
搜索
文章平均质量分 69
闻道-问道
这个作者很懒,什么都没留下…
展开
-
搜索--07
题目大概:一个人捉一头牛,他们在一条直线上,人和牛分别在一个位置上n,m,牛不动,人可以左走1,右走1,右走2*n,问最少几步人可以捉到牛。思路:用广搜。用队列存数据,每次都把该坐标下的三种走法存入队列,每次从队头取出数据判断是否捉到牛。代码:已更新#include <cstdio>#include <cstring>#include &l...原创 2017-05-11 10:21:35 · 281 阅读 · 0 评论 -
#1408 : The Lastest Time
描述What is latest time you can make with 4 digits A, B, C and D?For example if the 4 digits are 1, 0, 0, 0, you can make 4 times with them: 00:01, 00:10, 01:00, 10:00. The lastest time will be 10:00. N...原创 2018-04-01 20:06:55 · 250 阅读 · 0 评论 -
#1350 : Binary Watch(dfs)
描述Consider a binary watch with 5 binary digits to display hours (00 - 23) and 6 binary digits to display minutes (00 - 59).For example 11:26 is displayed as 01011:011010. Given a number x, output all...原创 2018-04-01 20:04:20 · 144 阅读 · 0 评论 -
#1518 : 最大集合
描述给定一个1-N的排列A[1], A[2], ... A[N],定义集合S[K] = {A[K], A[A[K]], A[A[A[K]]] ... }。 显然对于任意的K=1..N,S[K]都是有限集合。 你能求出其中包含整数最多的S[K]的大小吗?输入第一行包含一个整数N。(1 <= N <= 100000) 第二行包含N个两两不同的整数,A[1], A[2], ... A[...原创 2018-04-01 20:02:11 · 1230 阅读 · 0 评论 -
#1567 : 偶树的切分(简单dfs)
描述如果一棵树节点数目是偶数,那么就称这棵树是偶树。给定一棵N个节点的偶树(编号1~N),小Hi想知道他最多可以同时切断多少条边,使得剩下的森林中每一个联通分量都是一棵偶树。例如如下的偶树: 1 / | | \ 2 3 4 5 | 6可以切断1-2之间边使得剩下的每个联通分量都是偶树。输入第一行包含一个偶数N。 以下N-1行每行包含两个整数a和b,表示a和...原创 2018-03-13 22:36:15 · 361 阅读 · 0 评论 -
#1041 : 国庆出游(巧妙dfs)
描述小Hi和小Ho准备国庆期间去A国旅游。A国的城际交通比较有特色:它共有n座城市(编号1-n);城市之间恰好有n-1条公路相连,形成一个树形公路网。小Hi计划从A国首都(1号城市)出发,自驾遍历所有城市,并且经过每一条公路恰好两次——来回各一次——这样公路两旁的景色都不会错过。令小Hi苦恼的是他的小伙伴小Ho希望能以某种特定的顺序游历其中m个城市。例如按3-2-5的顺序游历这3座城市。(具体来讲...原创 2018-03-18 10:27:38 · 189 阅读 · 0 评论 -
Curling 2.0
Problem DescriptionOn 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 whic原创 2017-08-05 20:11:24 · 439 阅读 · 0 评论 -
CodeForces - 814B
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that a原创 2017-08-03 21:49:55 · 341 阅读 · 0 评论 -
洗牌,发牌
Problem DescriptionA common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips,S1 and S2, each stac原创 2017-08-02 21:31:19 · 250 阅读 · 0 评论 -
#1304 : 搜索一·24点
描述周末,小Hi和小Ho都在家待着。在收拾完房间时,小Ho偶然发现了一副扑克,于是两人考虑用这副扑克来打发时间。小Ho:玩点什么好呢?小Hi:两个人啊,不如来玩24点怎么样,不靠运气就靠实力的游戏。小Ho:好啊,好啊。<经过若干局游戏之后>小Ho:小Hi,你说如果要写个程序来玩24点会不会很复杂啊?小Hi:让我想想。<过了几分钟>小Hi:我知道了!其实很简单嘛。提示:24点...原创 2018-04-01 20:08:33 · 205 阅读 · 0 评论 -
#1716 : 继承顺位(dfs)
描述H国的国王有很多王子,这些王子各自也都有很多王孙,王孙又各自有很多后代…… 总之,H国王族的族谱形成了一棵以国王为根的树形结构。 根据H国的法律,王族的继承顺位这样规定的:假设A和B是两位王族1. 如果其中一位是另一位的直系父亲、祖先,则辈份高的王族继承顺位更高 2. 否则,假设C是A和B的最近公共祖先。显然A和B一定是C的两位不同子嗣的后代。其中C较年长的子嗣的后代的继承顺位更高按时间顺...原创 2018-04-04 20:33:47 · 903 阅读 · 1 评论 -
D. Labyrinth(bfs记忆化爆搜)
You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cel...原创 2018-10-16 17:12:48 · 508 阅读 · 0 评论 -
World Cup (dfs预处理)
Here is World Cup again, the top 32 teams come together to fight for the World Champion.The teams are assigned into 8 groups, with 4 teams in each group. Every two teams in the samegroup will play a...原创 2018-10-07 18:52:48 · 358 阅读 · 0 评论 -
Wrestling Match (dfs乱搞染色)
Nowadays, at least one wrestling match is held every year in our country. There are a lot of peoplein the game is “good player”, the rest is “bad player”. Now, Xiao Ming is referee of the wrestlingm...原创 2018-10-03 17:31:09 · 2075 阅读 · 0 评论 -
D. Recovering BST(dp+记忆化搜索)
Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing u...原创 2018-08-20 11:01:50 · 360 阅读 · 0 评论 -
MZL's endless loop(欧拉路径)
Problem DescriptionAs we all kown, MZL hates the endless loop deeply, and he commands you to solve this problem to end the loop.You are given an undirected graph with n vertexs and m edges. Please ...原创 2018-07-31 20:56:55 · 243 阅读 · 0 评论 -
D. Fair(多源bfs)
D. Fairtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputSome company is going to hold a fair in Byteland. There are nn towns in Byteland and mm two...原创 2018-05-30 21:17:54 · 903 阅读 · 3 评论 -
走格子(简单dfs)
题目描述 在平面上有n*n大小的正方形,定义正方形左下角坐标是(1,1),右下角坐标是(n,1)现在A君在左下角,他的初始方向是向右,他要在正方形内走m步当A君碰到边界或者已经走过的格子时,他便会逆时针转90°继续走,直到走完m步。现在给你两个整数n和m,请算出走完m步后A君的坐标。输入描述:输入一行两个整数n和m。输出描述:输出一行两个数表示A君的坐标。示例1输入复制3 3输出复制3 2备注:n...原创 2018-06-12 12:00:38 · 998 阅读 · 0 评论 -
Children of the Candy Corn
Problem 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原创 2017-08-04 21:46:14 · 232 阅读 · 0 评论 -
CodeForces - 814A
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.To get rid of原创 2017-08-03 21:43:11 · 317 阅读 · 0 评论 -
Network Saboteur
Problem DescriptionA university network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided the network into two subnetworks in原创 2017-08-03 21:39:27 · 318 阅读 · 0 评论 -
搜索--12
题目大概:输入3个数,为立方体的长宽高,再输入立方体中的每个位置的状态,有起点,终点,障碍物,可以通过的地方。计算起点到终点的最少步数。思路:建立一个三维的地图,每个点有六种走法。用广度优先搜索,用队列存储,不断把每个点的六种走法存到队列中,不断寻找终点,计算最少步数。感想:与二维的地图差不多,只是改成三维,走的方向多了。上一个博客忘记说了,每用完一次队列,一定要清空,...原创 2017-05-20 15:38:10 · 216 阅读 · 0 评论 -
搜索--20
题目大概:输入t组数据,每组数据输入一个n,有一个n*n的矩形,一个国际象棋的马,从给定的位置出发,到达指定的位置,问最少步数是多少。思路:用广度优先搜索,用队列存储数据,每走一步有八种可能 ,存符合规定的位置到队列中,计算出到达指定位置的最少步数。感想:一个地图搜索题。代码:#include #include #include using namespace s原创 2017-05-20 15:30:09 · 248 阅读 · 0 评论 -
搜索--04
题目大概:输入多组数据,每组数据有n,,k,表示一个n*n的矩形,由点和#组成,k个东西可以放到#的位置,问有多少种方法。思路:用深度优先搜索。先放第一个,然后第二个。。。依次放好。并做好标记,当本行放完就转到下一行,当这一列放好就做上标记当行数小于零时,说明这种方法不行了。当k个东西都放完时,方法数加一。代码:已更新#include <cstdio...原创 2017-05-08 19:22:00 · 233 阅读 · 0 评论 -
搜索--02
题目大概:输入n组数据,每组数据有j k 有一个j*k的矩形,一个国际象棋的马从(1,1)开始走,找出这个马走遍所有地方的路径,j时表示有A---某个字母,k是1---某个数字。思路:用深度优先搜索,把马走过的地方标记,并记录马走的步数,当走的步数等于j*k时,则表示全部走了一遍整个棋盘。感想:不要忘记回溯。代码:#include #include using n原创 2017-05-08 19:09:01 · 213 阅读 · 0 评论 -
搜索--17
题目大概:输入一个整数n,用1到n组成一个环,使得每两个相邻的数相加是素数。输出这个环,第一个数是1,如有多个环,按字典序输出。思路:由于这个题数据范围比较小n然后再用深搜,数字从小到大 ,不断搜索相邻是素数的数,但不要忘记最后一个数与1的和也要是素数。当选出了n个数时,输出。代码:#include #include using namespace std;int a原创 2017-05-11 10:51:10 · 256 阅读 · 0 评论 -
搜索--16
题目大概:输入n和m,是一个n*m的矩形,里面由*和@组成。找出有几组@。一组@是指,一个@符号在矩形中的八个方向上有@,那这两个@就算一组。思路:就是看看这个矩形域内有几团@。可以用深搜或广搜,不断查找,直到附近没有了@ 算一组。但要注意标记记录@是否被计算过。代码:已更新#include <cstdio>#include <cstring>...原创 2017-05-11 10:43:19 · 269 阅读 · 0 评论 -
搜索--15
题目大概:输出n根木棍的长度,把它们折成m根相同长度的木棍,问折成的最大长度是多少。思路:这个题是以前做过的一道非常坑爹的二分题。队精度要求较高。就是最后不能四舍五入。感想:这个也勉强算是广搜吧,不知道为什么吧这道题放在搜索里。代码:#include #include #include using namespace std; double l,r=0,mid;原创 2017-05-11 10:36:50 · 333 阅读 · 0 评论 -
搜索--08
题目大概:输入一个数n,输出的数只能含有0和1,而且这个数是n的倍数。思路:广搜,深搜都可做,深搜需要控制数不要超long long。广搜慢点,深搜更快。代码:广搜代码---------------已更新#include <iostream>#include <queue>#include <algorithm>#incl...原创 2017-05-11 10:30:05 · 224 阅读 · 0 评论 -
搜索--09
题目大概:输入n组数据,每组数据两个四位素数。让第一个四位数变到第二个四位数,每步只能改一个数,改后的数也必须是素数,问最少经过几步改变可以成功。思路:用广度优先搜索。先把所有的素数筛出来,方便判断,然后四位数一位一位的改变,把符合条件的数放到队列中,直到变为第二个数,输出改变次数。感想:数据过多,就把一类数据做成一个结构体,这样方便进队列,而且如果分多个队列,内存会不够。原创 2017-05-20 15:46:53 · 220 阅读 · 0 评论 -
搜索总结
经过初步学习搜索,知道了搜索分为广度优先搜索和深度优先搜索。广度优先搜索:顾名思义,就是搜索的范围比较广,它运用了队列的相关知识。就是如果有一个大山,有很多层,从山顶有很多路通往下一层,如果有一个人是从第一层开始找,找完第一层再找第二层,依次下去,这就是广度优先搜索。如果学过数据结构中的树,则就是从树的根部开始找,先找下一层的各个结点,然后再下一层的结点,一直持续下去。深度优先原创 2017-06-10 16:07:38 · 287 阅读 · 0 评论 -
F - F (dfs)
Farmer John has installed a new security system on the barn and now must issue a valid password to the cows in the herd. A valid password consists of L (3 <= L <= 15) different lower-case characters (原创 2017-08-10 20:53:32 · 244 阅读 · 0 评论 -
E - E (dfs)
The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows create a 5x5 rectilinear grid of digits parallel to the x an原创 2017-08-10 20:50:59 · 257 阅读 · 0 评论 -
倒水
Problem DescriptionYou are given two pots, having the volume of A and B liters respectively. The following operations can be performed:FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;DROP(i) e原创 2017-08-02 21:35:56 · 349 阅读 · 0 评论 -
Borg Maze (bfs+最小生成树)
Problem 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原创 2017-08-09 12:09:28 · 343 阅读 · 0 评论 -
Shredding Company (dfs)
Problem DescriptionYou have just been put in charge of developing a new shredder for the Shredding Company Although a "normal" shredder would just shred sheets of paper into little pieces so that...原创 2017-08-07 20:44:06 · 1407 阅读 · 0 评论 -
搜索--数独
Sudoku Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)Total Submission(s) : 7 Accepted Submission(s) : 6Special Judge Problem DescriptionSudoku is a very simp原创 2017-07-31 21:39:05 · 467 阅读 · 0 评论 -
搜索--06
DescriptionTechnicians in a pathology lab analyze digitized images of slides. Objects on a slide are selected for analysis by a mouse click on the object. The perimeter of the boundary of an obj原创 2017-06-03 20:54:36 · 222 阅读 · 0 评论 -
搜索--01
题目大概:多个路由器之间有很多线相连,相联的路由器之间信号不能一样,问最少有几种信号。思路:这其实是高中的染色问题。在一个平面上有很多相接的图,每两个相接的图有不同的颜色,问最少可以用多少种颜色把图涂好。这里有四色定理,就是最多是四种颜色。那就好办了,从一种颜色开始循环,每次给定一定数量的颜色开始涂色,开始递归,从第一个开始涂,并自动判定与它相邻的是否和他同一颜色,是则结束原创 2017-06-03 20:40:45 · 244 阅读 · 0 评论 -
HDU - 5438 (拓扑排序+dfs)
Betty owns a lot of ponds, some of them are connected with other ponds by pipes, and there will not be more than one pipe between two ponds. Each pond has a value vv. Now Betty wants to remove some p...原创 2019-01-26 21:11:30 · 254 阅读 · 0 评论