PAT甲级
文章平均质量分 69
PAT
xumingyukou
这个作者很懒,什么都没留下…
展开
-
1003 Emergency
1003 EmergencyAs 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 length of each road between any pair of ci原创 2022-03-11 18:22:55 · 85 阅读 · 0 评论 -
1013 Battle Over Cities
1013 Battle Over CitiesIt 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 highways t原创 2022-03-09 18:51:04 · 129 阅读 · 0 评论 -
1107 Social Clusters
1107 Social ClustersWhen register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of people who have some of their hobbies in common. You are suppos原创 2022-03-04 11:10:39 · 94 阅读 · 0 评论 -
1066 Root of AVL Tree
1066 Root of AVL Tree根据一组数构建平衡二叉树#include<cstdio>#include<algorithm>using namespace std;struct node{ int val; int height; node* left; node* right;}*root;int n, num;node* newNode(int i){ node* p = new node; p->val =原创 2022-03-03 16:47:41 · 271 阅读 · 0 评论 -
1099 Build A Binary
1099 Build A Binary Search TreeA 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’s key.The right subtree of a node contains原创 2022-03-03 13:33:40 · 57 阅读 · 0 评论 -
1064 Complete Binary Search Tree
1064 Complete Binary Search TreeA 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’s key.The right subtree of a node contains原创 2022-03-03 11:50:12 · 41 阅读 · 0 评论 -
1043 Is It a Binary
1043 Is It a Binary Search TreeA 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’s key.The right subtree of a node contains原创 2022-03-03 10:01:42 · 56 阅读 · 0 评论 -
1053 Path of Equal Weight
1053 Path of Equal WeightGiven 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 an原创 2022-03-02 17:31:41 · 202 阅读 · 1 评论 -
1004 Counting Leaves
1004 Counting LeavesA 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<N<100原创 2022-03-02 15:23:01 · 88 阅读 · 0 评论 -
1094 The Largest Generation
1094 The Largest GenerationA 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 input fil原创 2022-03-02 14:38:50 · 87 阅读 · 0 评论 -
1090 Highest Price in Supply Chain
1090 Highest Price in Supply Chain19#include<cstdio>#include<cmath>#include<vector>#include<queue>using namespace std;struct node{ int level; int father; vector<int> child;}nodes[100010];int n; //供应链中的总商家数i原创 2022-03-02 11:41:42 · 52 阅读 · 0 评论 -
1079 Total Sales of Supply Chain
1079 Total Sales of Supply ChainA 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 fr原创 2022-03-02 10:42:24 · 106 阅读 · 0 评论 -
1102 Invert a Binary Tree
1102 Invert a Binary TreeInput Specification:Each input file contains one test case. For each case, the first line gives a positive integer N (≤10) which is the total number of nodes in the tree – and hence the nodes are numbered from 0 to N−1. Then N li原创 2022-03-02 09:02:58 · 151 阅读 · 0 评论 -
1086 Tree Traversals
1086 Tree Traversals Again根据序列的入栈和出栈顺序(即树的前序遍历和中序遍历),构建二叉树并输出树的后序遍历#include<cstdio>#include<stack>#include<string.h>using namespace std;struct node{ int val; node* left; node* right;};stack<int> S;int n;int in[35]原创 2022-03-01 17:45:38 · 361 阅读 · 0 评论 -
1020 Tree Traversals
1020 Tree TraversalsSuppose 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.Input Speci原创 2022-03-01 17:05:20 · 61 阅读 · 0 评论 -
1091 Acute Stroke
1091 Acute StrokeOne 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原创 2022-03-01 13:54:37 · 68 阅读 · 0 评论 -
1103 Integer Factorization
1103 Integer FactorizationThe 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.Input S原创 2022-03-01 10:42:28 · 91 阅读 · 0 评论 -
1097 Deduplication on a Linked List
1097 Deduplication on a Linked ListGiven 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原创 2022-03-01 09:07:06 · 65 阅读 · 0 评论 -
1052 Linked List Sorting
1052 Linked List SortingA linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, you are suppos原创 2022-02-22 16:57:07 · 48 阅读 · 0 评论 -
1032 Sharing
1032 SharingTo 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, loading and being are stored as showed in原创 2022-02-22 16:00:08 · 71 阅读 · 0 评论 -
1074 Reversing Linked List
1074 Reversing Linked ListGiven 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.原创 2022-02-22 15:12:40 · 101 阅读 · 0 评论 -
1056 Mice and Rice
1056 Mice and RiceMice 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 Fat原创 2022-02-18 15:58:23 · 183 阅读 · 0 评论 -
1051 Pop Sequence
1051 Pop SequenceGiven 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 i原创 2022-02-18 14:25:44 · 279 阅读 · 0 评论 -
1022 Digital Library
1022 Digital LibraryA 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 re原创 2022-02-17 16:29:42 · 51 阅读 · 0 评论 -
1071 Speech Patterns
1071 Speech PatternsPeople 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 v原创 2022-02-17 14:52:11 · 62 阅读 · 0 评论 -
1054 The Dominant Color
1054 The Dominant ColorBehind 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 domina原创 2022-02-17 14:09:46 · 122 阅读 · 0 评论 -
1100 Mars Numbers
1100 Mars NumbersPeople 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, oct, nov, dec” on Mars, respectively.For the next higher digit原创 2022-02-16 10:57:33 · 51 阅读 · 0 评论 -
1060 Are They Equal
1060 Are They EqualIf 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原创 2022-02-16 09:47:49 · 134 阅读 · 0 评论 -
1063 Set Similarity
1063 Set SimilarityGiven 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原创 2022-02-15 17:54:50 · 131 阅读 · 0 评论 -
1047 Student List for Course
1047 Student List for CourseZhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.Input Specification:Each input fil原创 2022-02-15 16:46:01 · 75 阅读 · 0 评论 -
1039 Course List for Student
1039 Course List for StudentZhejiang 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 Specific原创 2022-02-15 16:05:51 · 42 阅读 · 0 评论 -
1069 The Black Hole
1069 The Black Hole of NumbersFor any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from原创 2022-02-15 14:42:36 · 184 阅读 · 0 评论 -
1101 Quick Sort
1101 Quick SortThere is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the pivot to it原创 2022-02-15 12:27:54 · 195 阅读 · 0 评论 -
1093 Count PAT‘s
1093 Count PAT’sThe string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.Now given any string, you are supposed to te原创 2022-02-15 10:57:13 · 40 阅读 · 0 评论 -
1029 Median
1029 MedianGiven an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 12, and the median of S2 = { 9, 10, 15, 16, 17 } is 15. The median of two sequences is defined原创 2022-02-15 10:08:51 · 220 阅读 · 0 评论 -
1044 Shopping in Mar
1044 Shopping in MarsShopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diam原创 2022-02-14 14:38:13 · 34 阅读 · 0 评论 -
1010 Radix
1010 Radix#include<cstdio>#include<algorithm>#include<string>#include<string.h>#include<iostream>#include<math.h>using namespace std;string n1;string n2;int tag;int radix;long long to_dec(string n,int radix原创 2022-02-14 13:39:08 · 53 阅读 · 0 评论 -
1085 Perfect Sequence
1085 Perfect SequenceGiven a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum numbers in the sequence, respectively.Now given a sequence and a p原创 2022-02-14 10:08:49 · 202 阅读 · 0 评论 -
1038 Recover the Smallest Number
1038 Recover the Smallest NumberGiven a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3原创 2022-02-12 16:12:48 · 116 阅读 · 0 评论 -
1067 Sort with Swap(0, i)
1067 Sort with Swap(0, i)Given any permutation of the numbers {0, 1, 2,…, N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may apply the swap op原创 2022-02-11 22:54:43 · 341 阅读 · 0 评论