PAT
时间领主大锤
人从过往的经验中得到的教训是,人从来不会从过往的经验中得到教
展开
-
PAT 甲级 1056 Mice and Rice (25分)
Mice and Riceis 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...原创 2020-02-10 11:12:18 · 262 阅读 · 0 评论 -
PAT 甲级 1051 Pop Sequence (25分)
Given a stack which can keepMnumbers at most. PushNnumbers in the order of 1, 2, 3, ...,Nand pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of t...原创 2020-02-08 22:47:11 · 172 阅读 · 0 评论 -
PAT 甲级 1045 Favorite Color Stripe (30分)
Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts...原创 2020-02-07 16:20:25 · 231 阅读 · 0 评论 -
PAT 甲级 1040 Longest Symmetric String (25分)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, givenIs PAT&TAP symmetric?, the longest symmetric sub-string iss PAT&TAP s, hence you ...原创 2020-02-06 21:19:42 · 127 阅读 · 0 评论 -
PAT 甲级 1034 Head 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 t...原创 2020-02-04 22:43:50 · 243 阅读 · 0 评论 -
PAT 甲级 1017 Queueing at Bank (25分)
Suppose a bank hasKwindows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow li...原创 2020-01-30 23:25:05 · 183 阅读 · 1 评论 -
PAT 甲级 1016 Phone Bills (25分)
A long-distance telephone company charges its customers by the following rules:Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When...原创 2020-01-30 11:57:40 · 120 阅读 · 0 评论 -
PAT 甲级 1013 Battle Over Cities (25分)
t 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...原创 2020-01-29 18:50:27 · 112 阅读 · 0 评论 -
PAT 甲级 1007 Maximum Subsequence Sum (25分)
Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequen...原创 2020-01-28 10:06:50 · 142 阅读 · 0 评论 -
PAT 甲级1143 Lowest Common Ancestor (30 分,一个测试点未过)
The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.A binary search tree (BST) is recursively defined as a binary tree which has ...原创 2019-08-12 21:18:03 · 439 阅读 · 0 评论 -
pat 甲级 1138 Postorder 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 number of the postorder traversal se...原创 2019-08-09 17:01:50 · 286 阅读 · 0 评论 -
PAT 甲级1129 Recommendation System (25分)
Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user's preference by the number of time...转载 2019-07-26 22:09:13 · 129 阅读 · 0 评论 -
PAT甲级 1147 Heaps (30 分)
In computer science, aheapis a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...转载 2019-07-25 20:59:05 · 202 阅读 · 0 评论 -
PAT甲级 1130 Infix Expression (25分)
Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with parentheses reflecting the precedences of the operators.Input Specification:Each input file contai...原创 2019-07-25 11:21:47 · 111 阅读 · 0 评论 -
PAT 甲级 1155 Heap Paths (30 分)
In computer science, aheapis a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...转载 2019-07-19 22:19:21 · 124 阅读 · 0 评论 -
PAT甲级 1154 Vertex Coloring (25 分)
Aproper vertex coloringis a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at mostkcolors is called a (proper)k...转载 2019-07-19 21:47:21 · 114 阅读 · 0 评论 -
pat甲级 1002 A+B for Polynomials (25 分)
This time, you are supposed to findA+BwhereAandBare two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the informa...原创 2019-07-19 15:34:54 · 139 阅读 · 0 评论 -
PAT 甲级 1001 A+B Format (20 分)
Calculatea+band output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specification:Each input ...原创 2020-01-21 17:20:09 · 100 阅读 · 0 评论 -
PAT 乙级 1078 字符串压缩与解压
文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示。例如 ccccc 就用 5c 来表示。如果字符没有重复,就原样输出。例如 aba 压缩后仍然是 aba。解压方法就是反过来,把形如 5c 这样的表示恢复为 ccccc。本题需要你根据压缩或解压的要求,对给定字符串进行处理。这里我们简单地假设原始字符串是完全由英文字母...原创 2019-02-27 11:15:25 · 311 阅读 · 0 评论 -
PAT 乙级 1050 螺旋矩阵
本题要求将给定的 N 个正整数按非递增的顺序,填入“螺旋矩阵”。所谓“螺旋矩阵”,是指从左上角第 1 个格子开始,按顺时针螺旋方向填充。要求矩阵的规模为 m 行 n 列,满足条件:m×n 等于 N;m≥n;且 m−n 取所有可能值中的最小值。输入格式:输入在第 1 行中给出一个正整数 N,第 2 行给出 N 个待填充的正整数。所有数字不超过 104,相邻数字以空格分隔。输出格式:...原创 2019-02-14 23:51:09 · 244 阅读 · 0 评论 -
PAT 乙级 1052 卖个萌
萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。简单起见,我们假设一个表情符号是按下列格式输出的:[左手]([左眼][口][右眼])[右手]现给出可选用的符号集合,请你按用户的要求输出表情。输入格式:输入首先在前三行顺序对应给出手、眼、口的可选符号集。每个符号括在一对方括号 []内。题目保证每个集合都至少有一个符号,并不超过 10 个符号;每个符号包含 1 到 4 ...原创 2019-02-15 12:07:38 · 188 阅读 · 0 评论 -
PAT乙级 1033 旧键盘打字
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?输入格式:输入在 2 行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过 105 个字符的串。可用的字符包括字母 [a-z, A-Z]、数字 0-9、以及下划线 _(代表空格)、,、.、-、+(代表上档键...转载 2019-02-09 20:54:22 · 118 阅读 · 0 评论 -
PAT乙级 1034 有理数四则运算
本题要求编写程序,计算 2 个有理数的和、差、积、商。输入格式:输入在一行中按照 a1/b1 a2/b2 的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分母不为 0。输出格式:分别在 4 行中按照 有理数1 运算符 有理数2 = 结果 的格式顺序输出 2 个有理数的和、差、积、商。注意输出的每个有理数必须是该有理数的最简形式 k a/b...原创 2019-02-10 11:42:31 · 201 阅读 · 0 评论 -
PAT乙级 1040 有几个PAT
字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T);第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位(T)。现给定字符串,问一共可以形成多少个 PAT?输入格式:输入只有一行,包含一个字符串,长度不超过105,只包含 P、A、T 三种字母。输出格式:在一行中输出给定字符串中包含多少个 ...原创 2019-02-11 19:35:28 · 198 阅读 · 1 评论 -
PAT乙级 1054 求平均值
本题的基本要求非常简单:给定 N 个实数,计算它们的平均值。但复杂的是有些输入数据可能是非法的。一个“合法”的输入是 [−1000,1000] 区间内的实数,并且最多精确到小数点后 2 位。当你计算平均值的时候,不能把那些非法的数据算在内。输入格式:输入第一行给出正整数 N(≤100)。随后一行给出 N 个实数,数字间以一个空格分隔。输出格式:对每个非法输入,在一行中输出 ERRO...原创 2019-02-18 15:26:21 · 273 阅读 · 0 评论 -
PAT 乙级 1072 开学寄语
下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面、理发、整衣,然后思过、读书、锻炼、明智、开悟、精进。而后必成大器也!本题要求你写个程序帮助这所学校的老师检查所有学生的物品,以助其成大器。输入格式:输入第一行给出两个正整数 N(≤ 1000)和 M(≤ 6),分别是学生人数和需...原创 2019-02-24 10:47:38 · 156 阅读 · 0 评论 -
PAT 乙级 1073 多选题常见计分法
批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 50% 分数;如果考生选择了任何一个错误的选项,则不能得分。本题就请你写个程序帮助老师批改多选题,并且指出哪道题的哪个选项错的人最多。输入格式:输入在第一行给出两个正整数 N(≤1000)和 M(≤100),分别是学生人数和多选题的个数。随后 M 行,每...原创 2019-02-24 11:34:58 · 358 阅读 · 0 评论 -
PAT 乙级 1060 爱丁顿数
英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数” E ,即满足有 E 天骑车超过 E 英里的最大整数 E。据说爱丁顿自己的 E 等于87。现给定某人 N 天的骑车距离,请你算出对应的爱丁顿数 E(≤N)。输入格式:输入第一行给出一个正整数 N (≤105),即连续骑车的天数;第二行给出 N 个非负整数,代表每天的骑车距离。输出格式:在一...原创 2019-02-19 15:50:28 · 148 阅读 · 0 评论 -
PAT 乙级 1090 危险品装箱
集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里。比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸。本题给定一张不相容物品的清单,需要你检查每一张集装箱货品清单,判断它们是否能装在同一只箱子里。输入格式:输入第一行给出两个正整数:N(≤104) 是成对的不相容物品的对数;M(≤100) 是集装箱货品清单的单数。随后数据分两大块给出。第一块有N行...原创 2019-03-01 22:19:35 · 164 阅读 · 0 评论 -
PAT 乙级 1088 三人行
子曰:“三人行,必有我师焉。择其善者而从之,其不善者而改之。”本题给定甲、乙、丙三个人的能力值关系为:甲的能力值确定是 2 位正整数;把甲的能力值的 2 个数字调换位置就是乙的能力值;甲乙两人能力差是丙的能力值的 X 倍;乙的能力值是丙的 Y 倍。请你指出谁比你强应“从之”,谁比你弱应“改之”。输入格式:输入在一行中给出三个数,依次为:M(你自己的能力值)、X 和 Y。三个数字均为不超...原创 2019-03-01 22:34:44 · 557 阅读 · 0 评论 -
PAT 乙级 1075 链表元素分类
给定一个单链表,请编写程序将链表元素进行分类排列,使得所有负值元素都排在非负值元素的前面,而 [0, K] 区间内的元素都排在大于 K 的元素前面。但每一类内部元素的顺序是不能改变的。例如:给定链表为 18→7→-4→0→5→-6→10→11→-2,K 为 10,则输出应该为 -4→-6→-2→7→0→5→10→18→11。输入格式:每个输入包含一个测试用例。每个测试用例第 1 行给出:第...原创 2019-02-26 10:58:32 · 166 阅读 · 0 评论 -
PAT 乙级 1084 外观数列
外观数列是指具有以下特点的整数序列:d, d1, d111, d113, d11231, d112213111, ...它从不等于 1 的数字d开始,序列的第 n+1 项是对第 n 项的描述。比如第 2 项表示第 1 项有 1 个d,所以就是d1;第 2 项是 1 个d(对应d1)和 1 个 1(对应 11),所以第 3 项就是d111。又比如第 4 项是d113,其描...原创 2019-03-01 22:46:49 · 150 阅读 · 0 评论 -
PAT 乙级 1079 延迟的回文数
给定一个 k+1 位的正整数 N,写成 ak⋯a1a0 的形式,其中对所有 i 有 0≤ai<10 且 ak>0。N 被称为一个回文数,当且仅当对所有 i 有 ai=ak−i。零也被定义为一个回文数。非回文数也可以通过一系列操作变出回文数。首先将该数字逆转,再将逆转数与该数相加,如果和还不是一个回文数,就重复这个逆转再相加的操作,直到一个回...原创 2019-02-27 00:18:18 · 178 阅读 · 0 评论 -
PAT 乙级1051 复数乘法
数可以写成 (A+Bi) 的常规形式,其中 A 是实部,B 是虚部,i 是虚数单位,满足 i2=−1;也可以写成极坐标下的指数形式 (R×e(Pi)),其中 R 是复数模,P 是辐角,i 是虚数单位,其等价于三角形式 (R(cos(P)+isin(P))。现给定两个复数的 R 和 P,要求输出两数乘积的常规形式。输入格式:输入在一行中依次给出两个复数的 R1, P1...原创 2019-02-14 22:03:53 · 168 阅读 · 0 评论