
从零开始的pat甲级
大厂gogogo
写好代码就不累
展开
-
1122 Hamiltonian Cycle (25分)
1122Hamiltonian Cycle(25分)The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a graph. Such a cycle is called a "Hamiltonian cycle".In this problem, you are supposed to tell if a given cycle is a Hamiltonian cycle.I..原创 2020-05-10 19:49:01 · 313 阅读 · 0 评论 -
1111 Online Map (30分)
1111Online 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-05-10 18:30:19 · 247 阅读 · 0 评论 -
1087 All Roads Lead to Rome (30分)
1087All 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 contain...原创 2020-05-10 13:18:30 · 201 阅读 · 0 评论 -
1034 Head of a Gang (30分)
1034Head 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 betweenAandB, we say thatAandBis related. The weight of a relation is defined to be the total time length of al...原创 2020-05-09 22:36:47 · 137 阅读 · 0 评论 -
1030 Travel Plan (30分)
1030Travel 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 de...原创 2020-05-07 22:33:17 · 185 阅读 · 0 评论 -
1003 Emergency (25分)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the l...原创 2020-05-07 21:14:08 · 190 阅读 · 0 评论 -
Dijkstra求最短路 I
给定一个n个点m条边的有向图,图中可能存在重边和自环,所有边权均为正值。请你求出1号点到n号点的最短距离,如果无法从1号点走到n号点,则输出-1。输入格式第一行包含整数n和m。接下来m行每行包含三个整数x,y,z,表示存在一条从点x到点y的有向边,边长为z。输出格式输出一个整数,表示1号点到n号点的最短距离。如果路径不存在,则输出-1。数据范围1≤n≤5001≤...原创 2020-05-07 20:40:47 · 375 阅读 · 0 评论 -
1094 The Largest Generation (25分)
1094The 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 w...原创 2020-05-05 17:09:55 · 175 阅读 · 0 评论 -
1053 Path of Equal Weight (30分)
1053Path of Equal Weight(30分)Given a non-empty tree with rootR, and with weightWiassigned to each tree nodeTi. Theweight of a path fromRtoLis defined to be the sum of the weights of...原创 2020-05-05 16:34:26 · 307 阅读 · 0 评论 -
1127 ZigZagging on a Tree (30分)
1127ZigZagging 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...原创 2020-05-05 14:03:46 · 135 阅读 · 0 评论 -
1115 Counting Nodes in a BST (30分)
1115Counting Nodes in a BST(30分)A 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 les...原创 2020-05-05 10:27:58 · 145 阅读 · 0 评论 -
1110 Complete Binary Tree (25分)
1110Complete Binary Tree(25分)Given a tree, you are supposed to tell if it is a complete binary tree.Input Specification:Each input file contains one test case. For each case, the first line...原创 2020-05-04 16:49:01 · 201 阅读 · 0 评论 -
1102 Invert a Binary Tree (25分)
1102Invert a Binary Tree(25分)The following is from Max Howell @twitter:Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard ...原创 2020-05-04 16:31:45 · 122 阅读 · 0 评论 -
1099 Build A Binary Search Tree (30分)
1099Build A Binary Search Tree(30分)A 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 ke...原创 2020-05-04 15:41:28 · 236 阅读 · 0 评论 -
1064 Complete Binary Search Tree (30分)
1064Complete Binary Search Tree(30分)A 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...原创 2020-05-04 15:12:34 · 228 阅读 · 0 评论 -
1043 Is It a Binary Search Tree (25分)
1043Is It a Binary Search Tree(25分)A 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 ke...原创 2020-05-04 14:16:14 · 303 阅读 · 0 评论 -
1021 Deepest Root (25分)
1021Deepest 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 h...原创 2020-05-04 10:18:29 · 224 阅读 · 1 评论 -
1086 Tree Traversals Again (25分)
1086Tree 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 f...原创 2020-05-03 22:31:48 · 131 阅读 · 0 评论 -
1119 Pre- and Post-order Traversals (30分)
1119Pre- and Post-order Traversals(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 tr...原创 2020-05-03 21:38:04 · 180 阅读 · 0 评论 -
1138 Postorder Traversal (25分)
1138Postorder 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 numb...原创 2020-05-03 19:04:52 · 148 阅读 · 0 评论 -
1020 Tree Traversals (25分)
1020Tree 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 t...原创 2020-05-03 18:17:13 · 217 阅读 · 0 评论 -
1004 Counting Leaves (30分)
1004Counting 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...原创 2020-05-02 17:34:59 · 482 阅读 · 0 评论 -
合并集合
一共有n个数,编号是1~n,最开始每个数各自在一个集合中。现在要进行m个操作,操作共有两种:“M a b”,将编号为a和b的两个数所在的集合合并,如果两个数已经在同一个集合中,则忽略这个操作; “Q a b”,询问编号为a和b的两个数是否在同一个集合中;输入格式第一行输入整数n和m。接下来m行,每行包含一个操作指令,指令为“M a b”或“Q a b”中的一种。输出格...原创 2020-05-02 16:50:13 · 413 阅读 · 0 评论 -
算法笔记胡凡PAT晴神宝典浙大计算机考研机试---------PAT考纲
二战!原创 2019-02-20 17:03:09 · 8601 阅读 · 0 评论 -
单链表
实现一个单链表,链表初始为空,支持三种操作:(1) 向链表头插入一个数;(2) 删除第k个插入的数后面的数;(3) 在第k个插入的数后插入一个数现在要对该链表进行M次操作,进行完所有操作后,从头到尾输出整个链表。注意:题目中第k个插入的数并不是指当前链表的第k个数。例如操作过程中一共插入了n个数,则按照插入的时间顺序,这n个数依次为:第1个插入的数,第2个插入的数,…第n...原创 2020-05-02 15:26:14 · 360 阅读 · 0 评论 -
数的范围
数的范围给定一个按照升序排列的长度为n的整数数组,以及 q 个查询。对于每个查询,返回一个元素k的起始位置和终止位置(位置从0开始计数)。如果数组中不存在该元素,则返回“-1 -1”。输入格式第一行包含整数n和q,表示数组长度和询问个数。第二行包含n个整数(均在1~10000范围内),表示完整数组。接下来q行,每行包含一个整数k,表示一个询问元素。输出格式共q行...原创 2020-04-30 20:25:28 · 450 阅读 · 0 评论 -
模板题 堆排序
堆排序输入一个长度为n的整数数列,从小到大输出前m小的数。输入格式第一行包含整数n和m。第二行包含n个整数,表示整数数列。输出格式共一行,包含m个整数,表示整数数列中前m小的数。数据范围1≤m≤n≤1051≤m≤n≤105,1≤数列中元素≤1091≤数列中元素≤109输入样例:5 34 5 1 3 2输出样例:1 2 3#inc...原创 2020-04-30 19:07:20 · 169 阅读 · 0 评论 -
1098 Insertion or Heap Sort (25分)
1098Insertion or Heap Sort(25分)According to Wikipedia:Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort remov...原创 2020-04-30 16:59:07 · 196 阅读 · 1 评论 -
1075 PAT Judge (25分)
1075PAT Judge(25分)The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT.Input Specificatio...原创 2020-04-29 17:50:08 · 189 阅读 · 0 评论 -
1052 Linked List Sorting (25分)
1052Linked List Sorting(25分)A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integerkeyand aNextpointer...原创 2020-04-29 14:57:03 · 157 阅读 · 0 评论 -
1039 Course List for Student (25分)
1039Course List for Student(25分)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 cou...原创 2020-04-28 20:49:41 · 126 阅读 · 0 评论 -
1028 List Sorting (25分)
1028List Sorting(25分)Excel can sort records according to any column. Now you are supposed to imitate this function.Input Specification:Each input file contains one test case. For each case, th...原创 2020-04-28 20:00:24 · 158 阅读 · 0 评论 -
1025 PAT Ranking (25分)
1025PAT Ranking(25分)Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several pla...原创 2020-04-28 19:26:54 · 164 阅读 · 0 评论 -
1022 Digital Library (30分)
1022Digital Library(30分)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 assigne...原创 2020-04-27 22:37:20 · 114 阅读 · 0 评论 -
1012 The Best Rank (25分)
1012The Best Rank(25分)To evaluate the performance of our first year CS majored students, we consider their grades of three courses only:C- C Programming Language,M- Mathematics (Calculus or Li...原创 2020-04-27 21:51:46 · 222 阅读 · 0 评论 -
1100 Mars Numbers (20分)
1100Mars Numbers(20分)People on Mars count their numbers with base 13:Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earth is called "jan, feb, mar, apr, may, jun, jly, aug, sep,...原创 2020-04-27 19:21:22 · 168 阅读 · 0 评论 -
1027 Colors in Mars (20分)
1027Colors in Mars(20分)People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits ar...原创 2020-04-27 17:28:17 · 166 阅读 · 0 评论 -
1015 Reversible Primes (20分)
1015Reversible Primes(20分)Areversible primein any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime becau...原创 2020-04-26 23:13:13 · 151 阅读 · 0 评论 -
1024 Palindromic Number (25分)
1024Palindromic Number(25分)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 ...原创 2020-04-26 22:26:48 · 145 阅读 · 0 评论 -
1023 Have Fun with Numbers (20分)
1023Have Fun with Numbers(20分)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 hap...原创 2020-04-26 21:36:46 · 112 阅读 · 0 评论