
★搜索
墓华
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
UVA-548 Tree(二叉树,DFS)
只是对着刘汝佳书依葫芦画瓢,主要记录一下自己的理解、心得。题目:UVA-548题目描述:一棵二叉树,每个结点都有不同的权值(1~10000的正整数),给出了其中序遍历(第一行)和后序遍历(第二行),找到一个叶子,使得它到根的路径的权和最小,如果有多解,该叶子的本身的权值应尽量小。首先是对DFS的理解。先序遍历(根->左子树->右子树):ABDECF中序遍历(左子树->...原创 2018-11-12 10:57:17 · 404 阅读 · 0 评论 -
[牛客竞赛] Applese 走迷宫(搜索,BFS)
链接:https://ac.nowcoder.com/acm/contest/330/C来源:牛客网题目描述精通程序设计的 Applese 双写了一个游戏。在这个游戏中,它被困在了一个 n×m 的迷宫中,它想要逃出这个迷宫。在迷宫中,有一些方格是水池,只有当 Applese 处于水属性的时候才可以通过;有一些方格是岩浆,只有当 Applese 是火属性的时候可以通过;有一些方格是墙...原创 2019-01-30 13:06:16 · 275 阅读 · 0 评论 -
蓝桥杯历届试题 - 分考场(DFS+剪枝)
链接:历届试题 - 分考场问题描述n个人参加某项特殊考试。为了公平,要求任何两个认识的人不能分在同一个考场。求是少需要分几个考场才能满足条件。输入格式第一行,一个整数n(1<n<100),表示参加考试的人数。第二行,一个整数m,表示接下来有m行数据以下m行每行的格式为:两个整数a,b,用空格分开 (1<=a,b<=n) 表示第a个人与第b个人认识。...原创 2019-03-23 15:09:59 · 271 阅读 · 0 评论 -
2017 ECNA Problm F: Keeping On Track (图,DFS)
Acmar and Ibmar are at war! You are in charge of a rail network that transports important supplies throughout the great state of Acmar during this delicate time. The rail system is made up of a set o...原创 2019-07-03 18:53:52 · 295 阅读 · 0 评论 -
树的重心——DFS求解
定义:树的重心也叫树的质心。对于一棵树n个节点的无根树,找到一个点,使得把树变成以该点为根的有根树时,最大子树的结点数最小。换句话说,删除这个点后最大连通块(一定是树)的结点数最小。性质:树中所有点到某个点的距离和中,到重心的距离和是最小的,如果有两个距离和,他们的距离和一样。把两棵树通过一条边相连,新的树的重心在原来两棵树重心的连线上。一棵树添加或者删除一个节点,树的重心最多只移...原创 2019-07-15 15:28:19 · 1206 阅读 · 1 评论 -
求树上结点的两两距离和——DFS求解
对于一颗N个结点的树,其N-1条边有各自的边权(长度),求树上所有结点两两之间的距离和,即:∑i=1n−1∑j=i+1ndistance(i,j)\sum_{i=1}^{n-1}\sum_{j=i+1}^{n}distance(i,j)i=1∑n−1j=i+1∑ndistance(i,j)分析:要求求 一棵N个结点的树 上 所有的任意两点之间的距离和;那么 任意一条边对距离和的贡...原创 2019-07-18 15:51:43 · 1655 阅读 · 0 评论 -
UVA-725 Division (简单暴力枚举)
刘汝佳书上例举的典型暴力枚举题~暴力枚举题要经过分析来尽量减少不必要的枚举。题目:UVA-725题目描述:输入正整数N,从小到大输出所有形如abcde/fghij=N的表达式,其中a-j恰好为数字0-9的一个排列(可以有前导0)(2=&lt;n&lt;=79)如果没有符合表达式,输出"There are no solutions for N."思路:①通过从小到大枚举abcde,得到...原创 2018-11-12 20:13:37 · 669 阅读 · 0 评论 -
UVA-10976 Fractions Again?!(分数拆分)(枚举)
题目:UVA-10976题目描述:输入正整数k,找到所有的正整数x≥y,使得 1/k = 1/x + 1/y样例输入: 样例输出:2 212 1/2 = 1/6 + 1/3 1/2 = 1/4 + 1/4 8 1/12 = 1/156 + 1/13 ...原创 2018-11-14 08:41:41 · 388 阅读 · 0 评论 -
PTA L2-025 分而治之( 图 )
链接:PTA L2-025分而治之,各个击破是兵家常用的策略之一。在战争中,我们希望首先攻下敌方的部分城市,使其剩余的城市变成孤立无援,然后再分头各个击破。为此参谋部提供了若干打击方案。本题就请你编写程序,判断每个方案的可行性。输入格式:输入在第一行给出两个正整数 N 和 M(均不超过10 000),分别为敌方城市个数(于是默认城市从 1 到 N 编号)和连接两城市的通路条数。随后 M...原创 2019-03-18 21:03:02 · 469 阅读 · 0 评论 -
PAT Advanced 1013 Battle Over Cities(图,DFS/并查集)
链接:PAT Advanced 1013It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know...原创 2019-01-28 11:12:15 · 268 阅读 · 0 评论 -
PAT Advanced1099 Build A Binary Search Tree(二叉查找树 BST)
链接:PAT Advanced1099A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node...原创 2019-01-23 15:09:06 · 185 阅读 · 0 评论 -
PAT Advanced1103 Integer Factorization(DFS)
链接:PAT Advanced1103 The K−P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K−P factorization...原创 2019-01-18 13:45:03 · 225 阅读 · 0 评论 -
PAT Advanced1091 Acute Stroke(BFS)
链接:PAT Advanced1091One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI sl...原创 2019-01-18 16:23:05 · 202 阅读 · 0 评论 -
洛谷 P1032 字串变换(BFS,字符串)
链接:洛谷 P1032这题要注意的点(keng)挺多的…题目描述已知有两个字串A,B及一组字串变换的规则(至多6个规则):A 1 -&amp;gt; B 1A 2 -&amp;gt; B 2 规则的含义为:在 A中的子串 A 1可以变换为 B 1,A 2 可以变换为 B 2…。例如:A=‘abcd’ B=’xyz’变换规则为:‘abc’-&amp;gt;‘xu’ ‘ud’-&a原创 2019-01-20 13:49:01 · 511 阅读 · 0 评论 -
洛谷 P1443 马的遍历(BFS)
链接:洛谷 P1443 题目描述有一个n*m的棋盘(1&lt;n,m&lt;=400),在某个点上有一个马,要求你计算出马到达棋盘上任意一个点最少要走几步输入格式:一行四个数据,棋盘的大小和马的坐标输出格式:一个n*m的矩阵,代表马到达某个点最少要走几步(左对齐,宽5格,不能到达则输出-1)输入样例#1:3 3 1 1输出样例#1:0 3 23 -1 12...原创 2019-01-20 15:22:09 · 1022 阅读 · 0 评论 -
PAT Advanced1020 Tree Traversals(二叉树)
链接:PAT Advanced1020Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversa...原创 2019-01-21 11:19:34 · 216 阅读 · 0 评论 -
PAT Advanced1053 Path of Equal Weight(DFS,树)
链接:PAT Advanced1053Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight of a path from R to L is defined to be the sum of the weights of all the nodes...原创 2019-01-21 15:22:31 · 159 阅读 · 0 评论 -
PAT Advanced1106 Lowest Price in Supply Chain(树,DFS)
链接:PAT Advanced1106A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root sup...原创 2019-01-22 11:04:07 · 157 阅读 · 0 评论 -
PAT Advanced1043 Is It a Binary Search Tree(二叉查找树 BST)
链接:PAT Advanced1043A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less thanthe node’...原创 2019-01-23 13:34:32 · 225 阅读 · 0 评论 -
PAT Advanced1064 Complete Binary Search Tree(二叉查找树 BST)
链接:PAT Advanced1064A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node...原创 2019-01-23 14:43:21 · 196 阅读 · 0 评论 -
2019CCPC-江西省赛 A-Cotree(树的重心)
链接:JXCPC A-CotreeAvin has two trees which are not connected. He asks you to add an edge between them to make them connected while minimizing the function ∑i=1n−1∑j=i+1ndistance(i,j)\sum_{i=1}^{n-1}\...原创 2019-07-21 20:05:55 · 1898 阅读 · 0 评论