![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
pat
文章平均质量分 60
柘木木
这个作者很懒,什么都没留下…
展开
-
1079 Total Sales of Supply Chain
有一个价格,在树上每过一层就要加价r/100, 然后到叶子结点也就是商贩,他们哪里有存货,要算如果把这些存货都买下来要多少钱。思路:这题就是对树进行深度优先搜索, 找出叶子结点的深度就知道要加多少次的价格了,最后再把总价算出来即可。0 9//0说明没有孩子,即叶子结点,此时9代表的就是存货量,也就是该叶子结点的权值。10个结点,1.80为起始价,1.00就是每经过一个商家要加的价格。3 2 3 5//就是0号结点有3个孩子结点编号分别是2,3,5。原创 2023-02-05 17:31:09 · 265 阅读 · 0 评论 -
PAT 甲级 A1087 All Roads Lead to Rome
DFS遍历路径,找出点权和最大或点权和最大且平均点权最大的路径。Dijkstra找出所有最短路径。原创 2022-08-05 21:17:06 · 117 阅读 · 0 评论 -
PAT 甲级 A1018 Public Bike Management
转存失败重新上传取消。原创 2022-08-05 09:55:33 · 85 阅读 · 0 评论 -
PAT 甲级 A1072 Gas Station
Organization 浙江大学。原创 2022-08-03 20:56:51 · 144 阅读 · 0 评论 -
PAT 甲级 A1030 Travel Plan
①本质路上的花费和路程是一样的,都是两点的边权,所以可以计算最有距离的时候,进行最少花费的优化,即当最小距离改变的时候,重新初始化花费,如果最小路径相同的情况下,再进行优化判断;②Dijstra只负责找出最短路径,DFS遍历最短路径树,从而在所有路径中找到满足最小花费的路径。.........原创 2022-08-01 10:42:45 · 116 阅读 · 0 评论 -
PAT 甲级 A1003 Emergency
思路因为是无负权无向图,可以用Dijkstra算法求出最短路径,用num存储从起点到某点的路径个数,用w来存储从起点到某点的最大点权数,前者只要有u到v的新路,最短路径的个数就增加,点权则需要和原来的w判断才决定要不要更新。题意给出n(5)个顶点,m(6)条边,给出起点和终点的编号。给出m条边的端点(无向图)和边权。求最短路径数和最短路径中的最大点权和。...原创 2022-07-31 10:59:21 · 138 阅读 · 0 评论 -
PAT 甲级 A1021 Deepest Root
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.Each input file contains one原创 2022-07-28 09:48:19 · 93 阅读 · 0 评论 -
PAT 甲级 A1013 Battle Over Cities
在图中删除某个结点,求图内重新连通需要多少根线,其实就是求不计某个顶点,连通块的个数,因为在删除某顶点后,两两连通块内加一根线就能使得图重新连通了。没必要真的把顶点删除,遇到就跳过就好了,这样再去找图内连通块的个数,连通起来要用的线==连通块个数-1;3个顶点,2个边长,删除3个结点(每次删一个,都是在原图内操作,删除互不影响)1,2有边,1,3有边,123是删除的结点。......原创 2022-07-25 17:06:36 · 115 阅读 · 0 评论 -
PAT 甲级 A1076 Forwards on Weibo
一个微博里面有n(7)个用户,每个用户可以相互关注,用户关注列表里面的人转发说说,用户可以接收得到(有向图,被关注(发说说)->关注者),给出转发层次L(3),转发的层次不能超过L,然后下列给出第i个人的关注列表(依据这个可以建造图),最后一行给出k个人,这k个人是编写说说的人,求在不超过转发层次的情况下,转发的人数有多少(给出连通块内的一个元素求连通块内元素个数)。①题目给出的是用户i的关注列表,关注表内的用户发信息,用户i是接收方,②每个连通块应该做到互不影响。因此是被关注->关注。...原创 2022-07-25 10:49:46 · 131 阅读 · 0 评论 -
PAT 甲级 A1034 Head of a Gang
用二维数组存储图,边权是通话时间,点权是这个人通话了多久,建好图后,遍历图内的连通块,深度优先搜索找该连通图内成员,一个连通块就是一个犯罪团伙,从中找到点权最大的就是头目,连通块内顶点的个数就是该团伙内的人数,用一个Map存放团伙头目的名字和团伙内的人数,因为map可以自动排序,从而满足题目要求按名字的字典顺序从小到大排列。............原创 2022-07-24 16:10:31 · 320 阅读 · 0 评论 -
PAT 甲级 A1098 Insertion or Heap Sort
有n个元素,给出两个序列,第一个序列是初始序列,第二个序列是插入排序过程或者堆排序过程中的序列,问这个中间序列是那个排序的序列,并输出这次中间排序的下一次排列。思路模拟插入排序和堆排序,排列过程中一次次对比就好了。...原创 2022-07-22 09:44:01 · 110 阅读 · 0 评论 -
PAT 甲级 A1107 Social Clusters
找元素有关系的集合,用并查集,但是这个题目给的不是直接的人物和人物的关系,而是人和喜欢活动的关系,因此要将第一个喜欢该活动的人记录下来作为人和喜欢活动的树的根节点,某个人可以通过这个活动树可以找到人和人之间的关系。有n给人物,遍历这n个人物,每个人物有k项喜欢得运动,在后面引出,如果这些人喜欢的活动有交集,则这些人物在一个社交圈内,问有几个社交圈?每个社交圈内有多少人,按从大到小的排列顺序输出;...原创 2022-07-20 17:37:25 · 149 阅读 · 0 评论 -
PAT 甲级 A1066 Root of AVL Tree
这个一颗AVL(平衡二叉)树,依次给出n个插入结点的权,求建完树后的根节点的权值是多少?直接建立一颗AVL树,AVL树比二叉查找树多了一个高度,还有调平衡。原创 2022-07-20 09:46:04 · 75 阅读 · 0 评论 -
PAT 甲级 A1004 Counting Leaves
BFS多一个level数组用来存储结点所在的层数,不然在同一个队列内分辨不出那个结点是那个层次的,然后遍历所有结点,是叶子结点就按照level数组找到其所在的层次,作为hashtable的下标来对叶子结点计数。给出n个结点,里面有m个非叶子结点,然后下面m行就是这些非叶子结点的编号,子结点数目和子节点编号,要求该树每层的叶子结点个数。(根节点编号为1,根节点所在层次编号为1)DFS就是遍历所有结点,用一个hashtable数组,i代表层数,来记录i层下的叶子结点个数。...原创 2022-07-14 21:01:09 · 118 阅读 · 0 评论 -
PAT 甲级 A 1106 Lowest Price in Supply Chain
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 products from one's supplier in a price P and原创 2022-07-14 16:16:05 · 69 阅读 · 0 评论 -
PAT 甲级 A1094 The Largest Generation
题意:告诉你有n个结点,其中有m个非叶子结点,然后给出非叶子结点该结点的编号,子结点个数和子节点的编号,要我们输出该树层数内结点最多的结点个数和该层的层数编号(根结点和层数都是从1开始编号)。思路: 因为给出的是编号和结点的关系,因此应该用静态建树比较方便,因为没有权重,所以就不用建造结构体了,直接用vector能放映父结点和子结点的关系就好了。可以用DFS来做这个题目,递归有两个参数根节点root和层次level,同层次的就用hashtable计数,最后面再遍历找出那个层次的结点最多就好了原创 2022-07-14 13:40:28 · 99 阅读 · 0 评论 -
PAT 甲级 A1079 Total Sales of Supply Chain
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 products from one's supplier in a price P and原创 2022-07-14 11:37:51 · 87 阅读 · 0 评论 -
PAT 甲级 1090 Highest Price in Supply Chain
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 products from one's supplier in a price P and原创 2022-07-14 10:40:45 · 80 阅读 · 0 评论 -
PAT 甲级 A1064 Complete Binary Search Tree
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:A Complete Binary Tree (CBT) is a tree that is completely filled, with the possible exception of the bottom level, which is filled from left to right.Now原创 2022-07-13 18:01:24 · 108 阅读 · 0 评论 -
PAT 甲级 A1053 Path of Equal Weight(树的遍历)
Given 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 along the path from R to any leaf node L.Now given any weighted tree, you are原创 2022-07-12 18:30:56 · 210 阅读 · 0 评论 -
PAT 甲级 A1102 Invert a Binary Tree
题意:从0开始到n,依次给出结点的左右孩子,确定一颗二叉树,然后反转该二叉树,输出该反转二叉树的层序遍历序列和中序遍历序列。思路:用后序遍历中对根结点操作时,将左右孩子的地址交换,即可做到整树反转,先反转,然后再层次遍历和中序遍历就好了,像这种直接给出孩子的地址(编号)的,用静态二叉树会好做一些;代码:...原创 2022-07-11 16:03:39 · 129 阅读 · 0 评论 -
PAT 甲级 A1086 Tree Traversals Again
题意:用栈出入栈(push,pop)来确定唯一的二叉树,已知其中一个序列是中序遍历,求后序遍历。分析:由题意知,按一定的进出栈的顺序,可以确定两个序列,因此,应该是进栈是一个遍历序列,出栈也是一个遍历序列,因为题目给出,"An inorder binary tree traversal",因此,有一个序列应该是中序遍历序列,而先序遍历是先访问根节点,和入栈顺序过程性质相识,可以先认为入栈顺序是先序遍历序列, 从而可以确定唯一二叉树,通过输出样例可以发现后序遍历序列和该二叉树的后序遍历序列一致,因此可以得出原创 2022-07-11 10:44:29 · 102 阅读 · 0 评论 -
PAT 甲级 A1020 Tree Traversals
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.Each input file contains one test原创 2022-07-10 16:44:34 · 164 阅读 · 0 评论 -
PAT 甲级 1091 Acute Stroke
One 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 slice, your job is to calculate the volume of the stroke core.Each input file c原创 2022-07-08 11:17:33 · 95 阅读 · 0 评论 -
PAT 甲级 1103 Integer Factorizatio
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.Each input file contains one test c原创 2022-07-07 11:36:28 · 113 阅读 · 0 评论 -
PAT 甲级 1097 Deduplication on a Linked List
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or absolute value of its key equals K will be kept. At the m原创 2022-06-18 22:52:44 · 85 阅读 · 0 评论 -
PAT 甲级/乙级 A1074/B 1025 Reversing Linked List
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4, you must output 4→3→2→1→5→6.Each input file contains on原创 2022-06-18 15:42:24 · 87 阅读 · 0 评论 -
PAT 甲级 1052 Linked List Sorting
A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer and a pointer to the next structure. Now given a linked list, you are supposed to sort the structures accord原创 2022-06-17 15:13:52 · 70 阅读 · 0 评论 -
PAT 甲级 1032 Sharing
To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example, and are stored as showed in Figure 1.Figure 1You are原创 2022-06-17 10:47:41 · 123 阅读 · 0 评论 -
PAT 甲级 1056 Mice and Rice
Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice as possible in order to become a FatMouse.First the pla原创 2022-06-15 15:05:09 · 297 阅读 · 0 评论 -
PAT 1051 Pop Sequence
Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obta原创 2022-06-15 09:33:16 · 52 阅读 · 0 评论 -
PAT 甲级 1100 Mars Numbers
ople on Mars count their numbers with base 13:For examples, the number 29 on Earth is called "hel mar" on Mars; and "elo nov" on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to wri原创 2022-06-14 16:20:33 · 61 阅读 · 0 评论 -
PAT 甲级 1071 Speech PatternsScore
People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker's identity, which is useful when validating, for exampl原创 2022-06-13 20:59:44 · 106 阅读 · 0 评论 -
PAT 甲级 1022 Digital Library
A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number as its ID. Given any query from a reader, you are suppose原创 2022-06-13 20:45:06 · 101 阅读 · 0 评论 -
PAT 1054 The Dominant Color
Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes more than原创 2022-06-10 22:21:38 · 67 阅读 · 0 评论 -
PAT 甲级 1060 Are They Equal
If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×105 with simple chopping. Now given the number of significant digits on a machine and two float numbers, you are su原创 2022-06-04 16:20:27 · 65 阅读 · 0 评论 -
PAT 甲级 1063 Set Similarity
Given two sets of integers, the similarity of the sets is defined to be Nc/Nt×100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of distinct numbers in the two sets. Your job is to calculate the s原创 2022-06-03 10:57:47 · 63 阅读 · 0 评论 -
PAT 甲级 1039 Course List for Student
Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.Input Specification:Each input file cont原创 2022-05-31 17:08:49 · 62 阅读 · 0 评论 -
PAT 甲级 1024 Palindromic Number
A number that will be the same when it is written forwards or backwards is known as aPalindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.Non-palindromic numbers can be paired with palindro...原创 2022-05-31 15:30:08 · 69 阅读 · 0 评论 -
pat 甲级 1023 Have Fun with Numbers
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a diffe原创 2022-05-30 21:45:43 · 125 阅读 · 0 评论