PAT
PAT刷题记录
zhang35
zhangjqfriend@gmail.com
展开
-
PAT甲级备考手册(附常见题型分类 C++实现)
常用函数isPrime()#include <cmath>bool isPrime(int n){ //用pow(n, 0.5)会超时,sqrt效率大增 for (int i=2; i<=sqrt(n); i++){ if (n%i==0){ return false; } } return true;}isNumber()#include<sstream>bool isNu原创 2020-09-04 17:24:55 · 835 阅读 · 0 评论 -
PAT甲级真题 1114 Family Property (25分) C++实现 (并查集)
题目This time, you are supposed to help us collect the data for family-owned property. Given each person’s family members, and the estate(房产)info under his/her own name, we need to know the size of each family, and the average area and number of sets of the原创 2020-09-04 11:44:26 · 295 阅读 · 0 评论 -
PAT甲级真题 1113 Integer Set Partition (25分) C++实现 (简单划分数组)
题目Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1 and n2 numbers, respectively. Let S1 and S2 denote the sums of all the numbers in A1 and A2, respectively. You are supposed to make t原创 2020-08-03 18:40:06 · 173 阅读 · 0 评论 -
PAT甲级真题 1112 Stucked Keyboard (20分) C++实现(键盘坏键问题)
题目On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen for k times.Now given a resulting string on screen, you are supposed to list all th原创 2020-08-02 21:32:16 · 409 阅读 · 0 评论 -
PAT甲级真题 1111 Online Map (30分) C++实现(两次dijkstra+dfs,复用封装函数)
题目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 any request.Input原创 2020-08-01 13:02:47 · 176 阅读 · 0 评论 -
PAT甲级真题 1110 Complete Binary Tree (25分) C++实现(判断完全二叉树)
题目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 gives a positive integer N (≤20) which is the total number of nodes in the tree – and hen原创 2020-08-01 12:46:33 · 244 阅读 · 0 评论 -
PAT甲级真题 1109 Group Photo (25分) C++实现(排队问题,左右横跳)
题目Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following:The number of people in each row must be N/K (round down to the nearest integer), with all the extra people (if any) standing in th原创 2020-08-01 12:32:47 · 432 阅读 · 0 评论 -
PAT甲级真题 1108 Finding Average (20分) C++实现(stringstream判断string转float/double是否合法)
题目he basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A legal input is a real number in [−1000,1000] and is accurate up to no more原创 2020-08-01 12:21:48 · 236 阅读 · 0 评论 -
PAT甲级真题 1107 Social Clusters (30分) C++实现(并查集:路径压缩+优先级)
题目When 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 supposed to find all th原创 2020-08-01 12:11:51 · 205 阅读 · 0 评论 -
PAT甲级真题 1106 Lowest Price in Supply Chain (25分) C++实现(dfs)
题目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原创 2020-07-30 20:03:18 · 227 阅读 · 0 评论 -
PAT甲级真题 1105 Spiral Matrix (25分) C++实现(画螺旋矩阵)
题目This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then move in a clockwise spiral. The matrix has m rows and n col原创 2020-07-30 18:37:29 · 231 阅读 · 0 评论 -
PAT甲级真题 1104 Sum of Number Segments (20分) C++实现(智力题,测试点3double精度坑点)
题目Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0原创 2020-07-30 18:18:34 · 227 阅读 · 0 评论 -
PAT甲级真题 1103 Integer Factorization (30分) C++实现(dfs+剪枝+备忘录,经典题目)
题目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.Input Specification:Each inpu原创 2020-07-28 19:41:56 · 279 阅读 · 0 评论 -
PAT甲级真题 1102 Invert a Binary Tree (25分) C++实现(找树根,层序、中序遍历翻转二叉树)
题目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 so fuck off.Now it’s your turn to prove that YOU CAN invert a binary tree!Input Specific原创 2020-07-28 19:21:10 · 243 阅读 · 0 评论 -
PAT甲级真题 1101 Quick Sort (25分) C++实现 (快排基准位置,与有序数列位置相同是必要非充分条件)
测试点2、3、5错误坑点测试点2格式错误,末尾要加换行。原创 2020-07-28 19:14:29 · 234 阅读 · 0 评论 -
PAT甲级真题 1100 Mars Numbers (20分) C++实现
题目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, oct, nov, dec” on Mars, respectively.For the next higher digit, Mars people n原创 2020-07-28 13:01:44 · 346 阅读 · 0 评论 -
PAT甲级真题 1098 Insertion or Heap Sort (25分) C++实现(插入排序、堆排序)
题目According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list原创 2020-07-27 10:19:37 · 205 阅读 · 0 评论 -
PAT甲级真题 1097 Deduplication on a Linked List (25分) C++实现(模拟链表判断重复值,两个map)
题目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 t原创 2020-07-27 08:55:16 · 275 阅读 · 0 评论 -
PAT甲级真题 1096 Consecutive Factors (20分) C++实现(不要被20分迷惑了,从2到sqrt(n)构造连乘因子)
题目Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3×5×6×7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maximum原创 2020-07-26 21:07:28 · 340 阅读 · 0 评论 -
PAT甲级真题 1095 Cars on Campus (30分) C++实现(结构体排序,匹配停车场in、out信息)
题目Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you are supposed to tell, at any specific time point, the原创 2020-07-25 18:53:56 · 377 阅读 · 0 评论 -
PAT甲级真题 1094 The Largest Generation (25分) C++实现(树的层序遍历,统计各层节点数)
题目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 input file contains one test case原创 2020-07-25 14:31:30 · 146 阅读 · 0 评论 -
PAT甲级真题 1093 Count PAT‘s (25分) C++实现(同PAT乙级真题 1040)
题目The 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 tell the number原创 2020-07-25 13:57:23 · 145 阅读 · 0 评论 -
PAT甲级真题 1092 To Buy or Not to Buy (20分) C++实现(vector模拟map统计元素数量)
题目Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in whole pieces. Hence Eva must check原创 2020-07-25 12:21:16 · 252 阅读 · 0 评论 -
PAT甲级真题 1091 Acute Stroke (30分) C++实现(bfs累计节点数,dfs会栈溢出)
题目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.Input Specif原创 2020-07-25 11:03:15 · 303 阅读 · 0 评论 -
PAT甲级真题 1090 Highest Price in Supply Chain (25分) C++实现(dfs)
题目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原创 2020-07-24 12:30:50 · 238 阅读 · 0 评论 -
PAT甲级真题 1089 Insert or Merge (25分) C++实现 (同乙级1035 插入与归并,注意测试点2、4)
题目According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list原创 2020-07-23 09:35:21 · 417 阅读 · 2 评论 -
PAT甲级真题 1088 Rational Arithmetic (20分) C++实现(有理数四则运算,简单模拟,注意测试点2、3)
题目For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient.Input Specification:Each input file contains one test case, which gives in one line the two rational numbers原创 2020-07-17 09:57:49 · 595 阅读 · 0 评论 -
PAT甲级真题 1087 All Roads Lead to Rome (30分) C++实现(Dijkstra+DFS,带权无向图最优最短路径)
题目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 one test case. For each case, the原创 2020-07-17 08:55:57 · 658 阅读 · 0 评论 -
PAT甲级真题 1086 Tree Traversals Again (25分) C++实现(由先序、中序求后序)
题目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(1); push(2); push(3); pop(); p原创 2020-07-15 16:04:07 · 229 阅读 · 0 评论 -
PAT甲级真题 1085 Perfect Sequence (25分) C++实现(排序、双指针,注意测试点5坑)
题目Given 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 parameter p, you are原创 2020-06-08 15:04:44 · 430 阅读 · 0 评论 -
PAT甲级真题 1084 Broken Keyboard (20分) C++实现(简单遍历搜索)
题目On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you are supposed to type, and the string that you actually type out, plea原创 2020-06-07 14:20:57 · 225 阅读 · 0 评论 -
PAT甲级真题 1083 List Grades (25分) C++实现(简单数组排序)
题目Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grad...原创 2020-04-01 20:33:27 · 165 阅读 · 0 评论 -
PAT甲级真题 1082 Read Number in Chinese (25分) C++实现(中文读数,分治法)
题目Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output “Fu” first if it is negative. For example, -123456789 is read as “Fu yi Yi er Qian sa...原创 2020-04-01 20:29:06 · 326 阅读 · 0 评论 -
PAT甲级真题 1081 Rational Sum (20分) C++实现(模拟分数加法)
题目Given N rational numbers in the form “numerator/denominator”, you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts with a positive ...原创 2020-04-01 20:08:33 · 229 阅读 · 0 评论 -
PAT甲级真题 1080 Graduate Admission (30分) C++实现(报志愿问题)
题目It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admis...原创 2020-03-31 10:14:02 · 236 阅读 · 0 评论 -
PAT甲级真题 1079 Total Sales of Supply Chain (25分) C++实现(带深度的DFS)
题目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 t...原创 2020-03-31 10:01:02 · 909 阅读 · 0 评论 -
PAT甲级真题 1078 Hashing (25分) C++实现(Quadratic probing 平方探测法解决hash冲突)
题目The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be “H(key) = ke...原创 2020-03-31 09:48:15 · 1043 阅读 · 1 评论 -
PAT甲级真题 1077 Kuchiguse (20分) C++实现(倒序搜索字符串公共尾部)
题目The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker’s personality. Such a preference is call...原创 2020-03-31 09:06:28 · 390 阅读 · 1 评论 -
PAT甲级真题 1076 Forwards on Weibo (30分) C++实现(图的广度优先遍历,BFS)
题目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...原创 2020-03-28 18:49:18 · 273 阅读 · 0 评论 -
PAT甲级真题 1075 PAT Judge (25分) C++实现(map+vector统计筛选排序,注意坑点)
题目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 Specification:Each input file c...原创 2020-03-28 16:59:28 · 248 阅读 · 0 评论