随笔分类 - 搜索:DFS(深度优先遍历)
摘要:链接:https://nanti.jisuanke.com/t/39277 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只有当两点在一条链上才存在,那么直接一遍dfs从根节点向下跑途中维护一下前缀和,把所有情况中不合理情况
阅读全文
摘要:恢复内容开始 L3-001 凑零钱 链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805054207279104 思路; 数据很小直接 dfs 代码: #include<bits/stdc++.h> using na
阅读全文
摘要:。。。天梯模拟赛没写出树的遍历。。。补几道类似的题 L2-004 这是二叉搜索树吗? 链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805070971912192 思路:先核对这串序列是否符合先序遍历,如果不符合再核
阅读全文
摘要:A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: B. Tanya and Candies 链接:http://codeforces.com/contest/1118/problem/B 题意:给你一串序列,去
阅读全文
摘要:A. Snowball 链接:http://codeforces.com/contest/1099/problem/A 思路:模拟 代码: B. Squares and Segments 链接:http://codeforces.com/contest/1099/problem/B 思路:思维题 实
阅读全文
摘要:Description “余”人国的国王想重新编制他的国家。他想把他的国家划分成若干个省,每个省都由他们王室联邦的一个成员来管理。他的国家有n个城市,编号为1..n。一些城市之间有道路相连,任意两个不同的城市之间有且仅有一条直接或间接的道路。为了防止管理太过分散,每个省至少要有B个城市,为了能有效的
阅读全文
摘要:题目链接:https://nanti.jisuanke.com/t/31451 题意: 给你一颗树,树上各点有初始权值,你有两种操作: 1. 给树中深度为l的点全部+x,(根节点为1,深度为0) 2.求出以x为根的子树权值和 思路: 因为第一个操作是对一整层的树节点+x,那么我们可以很容易的标记每一
阅读全文
摘要:链接: http://acm.hdu.edu.cn/showproblem.php?pid=6394 思路:用dfs序处理下树,在用分块,我们只需要维护当前这个点要跳出这个块需要的步数和他跳出这个块去到的下一个点的下标,这样更新和询问的复杂度就降到了sqrt(n),查询树上的点的时候我们可以用倍增来
阅读全文
摘要:poj1321 棋盘问题 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。 Input 输入含有多组测试数据。 每组数据的第一行是两个正整数,n k
阅读全文
摘要:The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of
阅读全文
摘要:给出一个字符串S(可能有重复的字符),按照字典序从小到大,输出S包括的字符组成的所有排列。例如:S = "1312", 输出为: 1123 1132 1213 1231 1312 1321 2113 2131 2311 3112 3121 3211 给出一个字符串S(可能有重复的字符),按照字典序从
阅读全文
摘要:LETTERS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8976 Accepted: 4017 Description A single-player game is played on a rectangular boa
阅读全文
摘要:The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a refrigerator. There are 16 handles on the ref
阅读全文
摘要:Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the other o
阅读全文
摘要:A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bran and his older siste
阅读全文
摘要: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 c
阅读全文
摘要:给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位置,只能走到与它相邻的4个位置中,当然在行走过程中,gloria不能走到迷宫外面去。令人头痛的是,g
阅读全文

浙公网安备 33010602011771号