dfs
shishiness
这个作者很懒,什么都没留下…
展开
-
pat 甲级 dfs A1103 Integer Factorization (30分)剪枝
1103 Integer Factorization (30分)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 of N for any positive integers N, K and P.原创 2020-07-25 10:39:01 · 105 阅读 · 0 评论 -
pat 甲级 树 A1004 Counting Leaves (30分)
1004 Counting Leaves (30分)A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one test case. Each case starts with a line containing 0<原创 2020-08-24 09:12:59 · 87 阅读 · 0 评论 -
pat 甲级 图 A1013 Battle Over Cities (25分) dfs
1013 Battle Over Cities (25分)It 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 immediately if we need to repair any other hig原创 2020-08-24 09:12:44 · 50 阅读 · 0 评论 -
pat 甲级 dijkstra A1087 All Roads Lead to Rome (30分)
1087 All Roads Lead to Rome (30分)Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness.Input Specification:Each input file contains o原创 2020-08-23 20:17:42 · 81 阅读 · 0 评论 -
pat 甲级 dijkstra A1030 Travel Plan (30分)
1030 Travel Plan (30分)A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting city and原创 2020-08-23 20:17:13 · 56 阅读 · 0 评论 -
pat 甲级 dijkstra A1018 Public Bike Management (30分)
1018 Public Bike Management (30分)There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city.The Public Bik原创 2020-08-23 20:17:02 · 66 阅读 · 0 评论 -
pat 甲级 dijkstra A1111 Online Map (30分)
1111 Online Map (30分)Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is guaranteed that a path exists for原创 2020-08-23 20:16:52 · 116 阅读 · 0 评论 -
pat 甲级 图 A1126 Eulerian Path (25分)欧拉图判别
1126 Eulerian Path (25分)In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were first discussed by Leonhard Euler原创 2020-08-23 20:16:24 · 77 阅读 · 0 评论 -
pat 甲级 图的遍历 A1034 Head of a Gang (30分)
1034 Head of a Gang (30分)One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be the total time length of all t原创 2020-07-25 10:58:39 · 64 阅读 · 0 评论 -
pat 甲级 树 A1151 LCA in a Binary Tree (30分)
1151 LCA in a Binary Tree (30分)The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.Given any two nodes in a binary tree, you are supposed to find their LCA.Input Specification:Eac原创 2020-08-22 18:11:11 · 65 阅读 · 0 评论 -
pat 甲级 树 A1135 Is It A Red-Black Tree (30分)红黑树
1135 Is It A Red-Black Tree (30分)There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties:(1) Every node is either red or black. (2) The root is black. (3) Every leaf (NULL) is black原创 2020-08-22 18:10:59 · 192 阅读 · 0 评论 -
pat 甲级 树 A1066 Root of AVL Tree (25分)
1066 Root of AVL Tree (25分)An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this prope原创 2020-08-22 18:10:41 · 78 阅读 · 0 评论 -
pat 甲级 堆 A1147 Heaps (30分)
1147 Heaps (30分)In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to原创 2020-08-22 18:10:10 · 74 阅读 · 0 评论 -
pat 甲级 堆 A1155 Heap Paths (30分)
1155 Heap Paths (30分)In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equ原创 2020-08-22 18:09:52 · 91 阅读 · 0 评论 -
pat 甲级树的遍历(建树解法和未建树解法)A1020 Tree Traversals (25分) (后序中序转层序)
1020 Tree Traversals (25分)Suppose 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 traversal sequence of the corresponding binary tree.Inp原创 2020-07-19 13:19:41 · 134 阅读 · 0 评论 -
pat 甲级 图的遍历 连通分量个数 dfs A1021 Deepest Root (25分)
1021 Deepest Root (25分)A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root.In原创 2020-07-19 12:29:13 · 133 阅读 · 0 评论 -
pat 甲级 广义树 A1079 Total Sales of Supply Chain (25分)
1079 Total Sales of Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys pro原创 2020-07-19 10:41:09 · 95 阅读 · 0 评论 -
pat 甲级 广义树 A1090 Highest Price in Supply Chain (25分)
1090 Highest Price in Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys p原创 2020-07-19 10:22:07 · 70 阅读 · 0 评论 -
pat 甲级 广义树 A1106 Lowest Price in Supply Chain (25分)
106 Lowest Price in Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys pro原创 2020-07-19 10:00:20 · 48 阅读 · 0 评论 -
pat 甲级 广义树 A1094 The Largest Generation (25分)
1094 The Largest Generation (25分)A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.Input Specification:Each原创 2020-07-19 09:31:03 · 72 阅读 · 0 评论 -
pat 甲级 树 1086 Tree Traversals Again (25分)
1086 Tree Traversals Again (25分)An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack operations are: push原创 2020-07-19 08:36:36 · 70 阅读 · 0 评论