
DFS和BFS
小·幸·运
你的所有努力最后都会回赠予你。
展开
-
PAT甲级A1004 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.InputEach input file contains one test case. Each case starts with a line co...原创 2018-07-19 21:35:21 · 179 阅读 · 0 评论 -
PAT甲级A1111 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 g...原创 2019-02-28 15:53:12 · 284 阅读 · 0 评论 -
PAT甲级A1079 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 th...原创 2019-02-19 14:58:47 · 240 阅读 · 0 评论 -
PAT甲级A1103 Integer Factorization (30 分)
The K−PK-PK−P factorization of a positive integer NNN is to write NNN as the sum of the PPP-th power of KKK positive integers. You are supposed to write a program to find the K−PK-PK−P factorization o...原创 2019-02-26 14:59:21 · 266 阅读 · 0 评论 -
PAT甲级A1106 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 th...原创 2019-02-26 19:35:57 · 170 阅读 · 0 评论 -
PAT甲级A1123 Is It a Complete AVL Tree (30 分)
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...原创 2019-03-08 15:43:01 · 159 阅读 · 0 评论 -
PAT甲级A1126 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 firs...原创 2019-03-08 17:29:10 · 215 阅读 · 0 评论 -
PAT甲级A1127 ZigZagging on a Tree (30 分)
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences. And it is a simple stand...原创 2019-03-08 19:44:16 · 258 阅读 · 0 评论 -
PAT甲级A1131 Subway Map (30 分)
In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed to help people with you...原创 2019-03-10 15:58:34 · 305 阅读 · 0 评论 -
PAT甲级A1155 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 (i...原创 2019-03-16 20:51:41 · 290 阅读 · 0 评论 -
PAT甲级A1094 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 ...原创 2019-02-23 20:14:22 · 185 阅读 · 0 评论 -
PAT甲级A1090 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 th...原创 2019-02-23 17:27:53 · 212 阅读 · 0 评论 -
PAT甲级A1013 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 nee...原创 2018-07-28 20:49:30 · 443 阅读 · 0 评论 -
PAT甲级A1021 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 ...原创 2018-08-09 22:20:38 · 153 阅读 · 0 评论 -
PAT甲级A1018 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 ...原创 2018-08-06 22:21:03 · 263 阅读 · 0 评论 -
PAT甲级A1030 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 b...原创 2018-08-18 20:31:46 · 165 阅读 · 0 评论 -
PAT甲级A1020 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 cor...原创 2018-08-07 22:28:58 · 158 阅读 · 0 评论 -
PAT甲级A1034 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 t...原创 2018-08-24 21:17:37 · 168 阅读 · 0 评论 -
PAT甲级A1053 Path of Equal Weight (30 分)
Given a non-empty tree with root RRR, and with weight WiW_iWi assigned to each tree node TiT_iTi. The weight of a path from RRR to LLL is defined to be the sum of the weights of all the nodes al...原创 2019-01-20 17:03:07 · 277 阅读 · 0 评论 -
PAT甲级A1087 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 ...原创 2019-02-21 21:25:59 · 375 阅读 · 0 评论 -
PAT甲级A1076 Forwards on Weibo (30 分)
Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a ...原创 2019-02-18 16:25:01 · 147 阅读 · 0 评论 -
PAT甲级A1138 Postorder Traversal (25 分)
Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal se...原创 2019-03-12 20:12:19 · 231 阅读 · 0 评论