PAT
文章平均质量分 80
记录PAT各类题集的解法
memcpy0
希望探索文理结合的自由之路。
展开
-
PAT 团体程序设计天梯赛-练习集 L2部分
文章目录L2-011 玩转二叉树 (25 分)L2-011 玩转二叉树 (25 分)题解见此处。原创 2021-05-29 03:19:20 · 140 阅读 · 0 评论 -
PAT真题模拟卷 题解汇总目录
文章目录PAT甲级仿真卷PAT(甲级)2011年秋季考试PAT甲级仿真卷PAT(甲级)2011年秋季考试原创 2021-05-29 02:04:47 · 323 阅读 · 1 评论 -
【PAT】2021年春季PAT甲级题解
文章目录1.题意解法2.题意解法3.题意解法4.题意解法1.Input Specification:Output Specification:Sample Input:Sample Output:题意解法2.Input Specification:Output Specification:Sample Input:Sample Output:题意解法3.Input Specification:Output Specification:Sample Input:Samp原创 2021-12-16 23:15:19 · 2220 阅读 · 0 评论 -
【PAT】2021年秋季PAT甲级题解
文章目录1. Arrays and Linked Lists (20 分)题意解法 模拟+数组2. Stack of Hats (25 分)题意解法 排序3. Playground Exploration (25 分)题意解法 图+DFS+贪心4. Sorted Cartesian Tree (30 分)题意解法 笛卡尔树+递归+左旋/右旋1. Arrays and Linked Lists (20 分)Let’s design a data structure AAA that combines a原创 2021-12-10 21:58:15 · 2002 阅读 · 0 评论 -
PAT基础级-黄金段位样卷1
文章目录7-1 装睡 (10 分)7-2 电子汪 (10 分)7-3 到底是不是太胖了 (10 分)7-4 到底有多二 (15 分)7-5 一帮一 (15 分)7-1 装睡 (10 分)你永远叫不醒一个装睡的人 —— 但是通过分析一个人的呼吸频率和脉搏,你可以发现谁在装睡!医生告诉我们,正常人睡眠时的呼吸频率是每分钟15-20次,脉搏是每分钟50-70次。下面给定一系列人的呼吸频率与脉搏,请你找出他们中间有可能在装睡的人,即至少一项指标不在正常范围内的人。输入格式:输入在第一行给出一个正整数 N(≤原创 2021-05-31 00:56:02 · 3144 阅读 · 1 评论 -
【PAT甲级】1014 Waiting in Line (30 分)
Suppose a bank has NNN windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:The space inside the yellow line in front of each window is eno原创 2021-05-29 05:27:44 · 326 阅读 · 0 评论 -
【PAT甲级】1013 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 need to repair any other highways to keep the rest of the c原创 2021-05-29 04:00:54 · 159 阅读 · 1 评论 -
PAT 数据结构与算法题目集(中文)题解汇总
7-35 城市间紧急救援 (25 分)原创 2021-05-29 03:26:40 · 637 阅读 · 0 评论 -
数据结构与算法题目集(中文)7-35 城市间紧急救援 (25 分)
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上。当其他城市有紧急求助电话给你的时候,你的任务是带领你的救援队尽快赶往事发地,同时,一路上召集尽可能多的救援队。输入格式:输入第一行给出4个正整数 NNN、MMM、SSS、DDD,其中 NNN(2≤N≤5002≤N≤5002≤N≤500)是城市的个数,顺便假设城市的编号为 0∼(N?1)0 \sim (N?1)0∼(N?1)原创 2021-05-29 03:24:41 · 290 阅读 · 0 评论 -
PAT 团体程序设计天梯赛-练习集 L2-001 紧急救援 (25 分)
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上。当其他城市有紧急求助电话给你的时候,你的任务是带领你的救援队尽快赶往事发地,同时,一路上召集尽可能多的救援队。输入格式:输入第一行给出4个正整数 NNN、MMM、SSS、DDD,其中 NNN(2≤N≤5002≤N≤5002≤N≤500)是城市的个数,顺便假设城市的编号为 0∼(N−1)0 \sim (N−1)0∼(N−1)原创 2021-05-29 03:17:41 · 346 阅读 · 0 评论 -
PAT 团体程序设计天梯赛-练习集 L1部分
文章目录L1-001 Hello World (5 分)L1-002 打印沙漏 (20 分)L1-001 Hello World (5 分)这道超级简单的题目没有任何输入。你只需要在一行中输出著名短句“Hello World!”就可以了。输入样例:无输出样例:Hello World!代码如下:#include <bits/stdc++.h>using namespace std;int main() { printf("Hello World!"); r原创 2021-05-28 04:42:31 · 213 阅读 · 0 评论 -
PAT 团体程序设计天梯赛-练习集 L2-011 玩转二叉树 (25 分)
给定一棵二叉树的中序遍历和前序遍历,请你先将树做个镜面反转,再输出反转后的层序遍历的序列。所谓镜面反转,是指将所有非叶结点的左右孩子对换。这里假设键值都是互不相等的正整数。输入格式:输入第一行给出一个正整数 NNN(≤30≤30≤30),是二叉树中结点的个数。第二行给出其中序遍历序列。第三行给出其前序遍历序列。数字间以空格分隔。输出格式:在一行中输出该树反转后的层序遍历的序列。数字间以1个空格分隔,行首尾不得有多余空格。输入样例:71 2 3 4 5 6 74 1 3 2 6 5 7输出原创 2021-05-28 06:49:09 · 145 阅读 · 0 评论 -
PAT基础级-白银段位样卷1
文章目录7-1 日期格式化7-2 是不是太胖了7-3 A除以B7-4 装睡7-5 电子汪7-6 到底是不是太胖了7-1 日期格式化世界上不同国家有不同的写日期的习惯。比如美国人习惯写成“月-日-年”,而中国人习惯写成“年-月-日”。下面请你写个程序,自动把读入的美国格式的日期改写成中国习惯的日期。输入格式:输入在一行中按照“mm-dd-yyyy”的格式给出月、日、年。题目保证给出的日期是1900年元旦至今合法的日期。输出格式:在一行中按照“yyyy-mm-dd”的格式给出年、月、日。输入样例:原创 2021-05-28 23:04:08 · 282 阅读 · 0 评论 -
PAT基础级-青铜段位样卷1
文章目录7-1 新世界7-2 日期格式化7-3 后天7-4 是不是太胖了7-5 A除以B7-1 新世界这道超级简单的题目没有任何输入。你只需要在第一行中输出程序员钦定名言“Hello World”,并且在第二行中输出更新版的“Hello New World”就可以了。代码如下:#include <iostream>using namespace std;int main() { cout <<"Hello World\n"; cout <<原创 2021-05-28 21:05:08 · 327 阅读 · 0 评论 -
PAT基础级-黄金段位样卷2
文章目录7-1 PTA使我精神焕发7-2 宇宙无敌大招呼7-3 谁是赢家7-4 大笨钟7-5 幸运彩票7-6 福到了7-1 PTA使我精神焕发以上是湖北经济学院同学的大作。本题就请你用汉语拼音输出这句话。输入格式:本题没有输入。输出格式:在一行中按照样例输出,以惊叹号结尾。输入样例:无输出样例:PTA shi3 wo3 jing1 shen2 huan4 fa1 !代码如下:#include <iostream>using namespace std;int ma原创 2021-05-28 20:05:09 · 2137 阅读 · 0 评论 -
PAT 线上测试赛真题(2020-05-01)
文章目录7-1 Knuth洗牌法 (20 分)7-2 三阶幸福数 (20 分)7-3 垃圾分类 (20 分)7-1 Knuth洗牌法 (20 分)Knuth 洗牌法是生成 { 1, 2, …, n } 的一个随机重排列的算法。与每次反复随机生成一个数字,直到获得一个不重复的新数字的算法不同,Knuth 洗牌法从原始序列 { 1, 2, …, n } 开始,逐次洗牌。洗牌的方法是从左到右,每轮从没确定的数字中随机抽取一个数,把它放到确定的位置上。例如令 n 等于 4。我们从 { 1, 2, 3, 4原创 2021-05-28 19:44:37 · 334 阅读 · 0 评论 -
PAT基础级-白银段位样卷2
文章目录7-1 A乘以B7-2 心理阴影面积7-3 新胖子公式7-4 谁是赢家7-5 求整数段和7-6 寻找2507-1 A乘以B看我没骗你吧 —— 这是一道你可以在10秒内完成的题:给定两个绝对值不超过100的整数A和B,输出A乘以B的值。输入格式:输入在第一行给出两个整数 AAA 和 BBB(−100≤A,B≤100−100≤A,B≤100−100≤A,B≤100),数字间以空格分隔。输出格式:在一行中输出A乘以B的值。输入样例:-8 13输出样例:-104代码如下:#inc原创 2021-05-28 15:05:13 · 612 阅读 · 0 评论 -
PAT基础级-青铜段位样卷2
文章目录7-1 简单题 (5 分)7-2 A乘以B (5 分)7-3 心理阴影面积 (5 分)7-4 宇宙无敌大招呼 (5 分)7-5 新胖子公式 (10 分)7-1 简单题 (5 分)这次真的没骗你 —— 这道超级简单的题目没有任何输入。你只需要在一行中输出事实:This is a simple problem. 就可以了。输入样例:无输出样例:This is a simple problem.代码如下:#include <bits/stdc++.h>int main()原创 2021-05-27 22:12:02 · 386 阅读 · 0 评论 -
【PAT甲级】1011 World Cup Betting (20分)
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money原创 2020-11-02 15:44:49 · 148 阅读 · 0 评论 -
【PAT顶级】1027 Larry and Inversions (35 分)【树状数组】
Larry just studied the algorithm to count number of inversions. He’s very interested in it. He’s considering another problem: Given a permutation of integers from 1 to n, how many inversions it has if we reverse one of its subarray?Formally speaking, give原创 2021-05-22 19:31:56 · 152 阅读 · 0 评论 -
【PAT顶级】1008 Airline Routes (35 分)【强连通分量】
Given a map of airline routes, you are supposed to check if a round trip can be planned between any pair of cities.Input Specification:Each input file contains one test case. For each case, the first line gives two positive integers N(2≤N≤104N (2≤N≤10^4N原创 2021-05-22 19:26:27 · 207 阅读 · 0 评论 -
【PAT顶级】1010 Lehmer Code (35 分)【树状数组/离散化】
According to Wikipedia: “In mathematics and in particular in combinatorics, the Lehmer code is a particular way to encode each possible permutation of a sequence of nnn numbers.” To be more specific, for a given permutation of items {A1,A2,…,AnA_1, A_2, \d原创 2021-05-22 19:22:25 · 226 阅读 · 0 评论 -
【PAT顶级】1026 String of Colorful Beads (35 分)【滑动窗口/哈希表】
Eva would like to buy a string of beads with no repeated colors so she went to a small shop of which the owner had a very long string of beads. However the owner would only like to cut one piece at a time for his customer. With as many as ten thousand bead原创 2021-05-22 19:18:08 · 147 阅读 · 0 评论 -
【PAT顶级】1009 Triple Inversions (35 分)【树状数组】
Given a list of NNN integers A1,A2,A3,…,ANA_1, A_2, A_3, \dots, A_NA1,A2,A3,…,AN there’s a famous problem to count the number of inversions in it. An inversion is defined as a piar of indices i<ji<ji<j such that Ai>AjA_i>A_jA原创 2021-05-22 19:15:08 · 165 阅读 · 0 评论 -
【PAT甲级】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 length of each road between any pair of cities are marked原创 2020-10-27 16:07:35 · 58 阅读 · 0 评论 -
【PAT顶级】1016 Uniqueness of MST (35 分)【最小生成树/唯一最小生成树】
Given any weighted undirected graph, there exists at least one minimum spanning tree (MST) if the graph is connected. Sometimes the MST may not be unique though. Here you are supposed to calculate the minimum total weight of the MST, and also tell if it is原创 2021-05-22 19:10:37 · 1468 阅读 · 0 评论 -
【PAT顶级】1003 Universal Travel Sites (35 分)【最大流】
After finishing her tour around the Earth, CYLL is now planning a universal travel sites development project. After a careful investigation, she has a list of capacities of all the satellite transportation stations in hand. To estimate a budget, she must k原创 2021-05-22 19:05:54 · 1397 阅读 · 0 评论 -
【PAT顶级】1002 Business (35 分)【动态规划(01背包)】
As the manager of your company, you have to carefully consider, for each project, the time taken to finish it, the deadline, and the profit you can gain, in order to decide if your group should take this project. For example, given 3 projects as the follow原创 2021-05-22 19:02:31 · 462 阅读 · 0 评论 -
【PAT顶级】1001 Battle Over Cities - Hard Version (35 分)【最小生成树】
It is vitally important to have all the cities connected by highways in a war. If a city is conquered by the enemy, all the highways from/toward that city will be closed. To keep the rest of the cities connected, we must repair some highways with the minim原创 2021-05-22 18:58:54 · 203 阅读 · 0 评论 -
基础编程题目集 函数题部分
文章目录6-1 简单输出整数 (10分)6-2 多项式求值 (15分)6-3 简单求和 (10分)6-4 求自定类型元素的平均 (10分)6-5 求自定类型元素的最大值 (10分)6-6 求单链表结点的阶乘和 (15分)6-7 统计某类完全平方数 (20分)6-8 简单阶乘计算 (10分)6-9 统计个位数字 (15分)6-12 判断奇偶性 (10分)6-13 折半查找 (15分)做这些简单的题...原创 2020-01-22 21:24:16 · 2548 阅读 · 0 评论 -
基础编程题目集 编程题部分
★★ 7-22 龟兔赛跑 (20分)★★★ 7-23 币值转换 (20分) 中文习惯读数字 【约瑟夫环】7-28 猴子选大王 (20分)★ 7-29 删除字符串中的子串 (20分)★★★ 7-37 整数分解为若干项之和 (20分)★★★ 7-38 数列求和-加强版 (20分)原创 2020-02-17 16:31:22 · 5993 阅读 · 4 评论 -
PTA 520 钻石争霸赛 2021 大勾股定理 (15 分)【数学】
大勾股定理是勾股定理的推广:对任何正整数 nnn 存在 2n+12n+12n+1 个连续正整数,满足前 n+1n+1n+1 个数的平方和等于后 nnn 个数的平方和。例如对于 n=1n=1n=1 有 32+42=523^2+4^2=5^232+42=52 ;n=2n=2n=2 有 102+112+122=132+14210^2+11^2+12^2=13^2+14^2102+112+122=132+142 等。给定 nnn原创 2021-05-20 23:40:31 · 586 阅读 · 5 评论 -
浙大版《C语言程序设计(第3版)》题目集 函数题部分 45道
文章目录练习5-1 求m到n之和 (10分)练习5-2 找两个数中最大者 (10分)练习5-3 数字金字塔 (15分)习题5-1 符号函数 (10分)习题5-2 使用函数求奇数和 (15分)习题5-3 使用函数计算两点间的距离 (10分)练习5-1 求m到n之和 (10分)本题要求实现一个计算m~n(m<n)之间所有整数的和的简单函数。函数接口定义:int sum( int m, i...原创 2020-02-16 01:45:15 · 17060 阅读 · 13 评论 -
PTA 520 钻石争霸赛 2021
有一道题没来得及做,目前的排名是57,不知道后面会被挤到哪里。原创 2021-05-20 17:25:32 · 1311 阅读 · 10 评论 -
【PAT甲级】A1101-A1155刷题记录
文章目录(递推) A1101 Quick Sort (25 分) 0.23(二叉树遍历) A1102 Invert a Binary Tree (25 分) 0.51A1104 Sum of Number Segments (20 分) 0.32A1106 Lowest Price in Supply Chain (25 分) 0.42(并查集) A1107 Social Clusters (30...原创 2019-09-08 01:35:15 · 1635 阅读 · 0 评论 -
【PAT甲级】A1051-A1100刷题记录
文章目录(栈) A1051 Pop Sequence (25 分) 0.47(静态链表) A1052 Linked List Sorting (25 分) 0.21(静态树+先根遍历DFS) A1053 Path of Equal Weight (30 分) 0.45A1054 The Dominant Color (20 分) 0.50A1055 The World's Richest (25 ...原创 2019-09-08 01:35:07 · 963 阅读 · 0 评论 -
【PAT甲级】A1001-A1050刷题记录
文章目录A1001 A+B Format (20 分)★(一元多项式加法) A1002 A+B for Polynomials (25 分)A1003 Emergency 25 10635 38385 0.28A1004 Counting Leaves 30 7547 21375 0.35A1005 Spell It Right 20 8300 24226 0.34A1006 Sign In an...原创 2019-09-08 00:34:30 · 7512 阅读 · 0 评论 -
【PAT乙级】B1001-B1095刷题记录
本文记录了我刷PAT题目的解法和思维原创 2019-09-07 22:58:36 · 3683 阅读 · 1 评论 -
【约瑟夫环】PTA 基础编程题目集 编程题部分 7-28 猴子选大王 (20分)
一群猴子要选新猴王。新猴王的选择方法是:让N只候选猴子围成一圈,从某位置起顺序编号为1~N号。从第1号开始报数,每轮从1报到3,凡报到3的猴子即退出圈子,接着又从紧邻的下一只猴子开始同样的报数。如此不断循环,最后剩下的一只猴子就选为猴王。请问是原来第几号猴子当选猴王?输入格式:输入在一行中给一个正整数N(≤1000)。输出格式:在一行中输出当选猴王的编号。输入样例:11输出样例:...原创 2020-02-14 15:39:58 · 982 阅读 · 0 评论