pat
文章平均质量分 89
mlm5678
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PAT 1069. 微博转发抽奖
小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包。请你编写程序帮助他确定中奖名单。输入格式:输入第一行给出三个正整数 M(≤1000)、N 和 S,分别是转发的总量、小明决定的中奖间隔、以及第一位中奖者的序号(编号从 1 开始)。随后 M 行,顺序给出转发微博的网友的昵称(不超过 20 个字符、不包含空格回车的非空字符串)。注...原创 2018-08-29 11:06:11 · 177 阅读 · 0 评论 -
PAT乙级—1045. 快速排序(25)
著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边。 给定划分后的N个互不相同的正整数的排列,请问有多少个元素可能是划分前选取的主元?例如给定N = 5, 排列是1、3、2、4、5。则:1的左边没有元素,右边的元素都比它大,所以它可能是主元; 尽管3的左边元素都比它小,但是它右边的2它...原创 2018-08-23 18:10:26 · 181 阅读 · 0 评论 -
PAT 1068 万绿丛中一点红
对于计算机而言,颜色不过是像素点对应的一个 24 位的数值。现给定一幅分辨率为M×N的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的颜色与其周围 8 个相邻像素的颜色差充分大。输入格式:输入第一行给出三个正整数,分别是M和N(≤1000),即图像的分辨率;以及 TOL,是所求像素点与相邻点的颜色差阈值,色差超过 TOL 的点才被考虑。随后N行,每行...原创 2018-08-27 23:49:59 · 195 阅读 · 0 评论 -
PAT Basic 1065. 单身狗
“单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱。输入格式:输入第一行给出一个正整数 N(≤50 000),是已知夫妻/伴侣的对数;随后 N 行,每行给出一对夫妻/伴侣——为方便起见,每人对应一个 ID 号,为 5 位数字(从 00000 到 99999),ID 间以空格分隔;之后给出一个正整数 M(≤10 000),为参加派对的总人...原创 2018-08-27 12:21:29 · 362 阅读 · 0 评论 -
PAT 1064 朋友数
如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋友证号”。例如 123 和 51 就是朋友数,因为 1+2+3 = 5+1 = 6,而 6 就是它们的朋友证号。给定一些整数,要求你统计一下它们中有多少个不同的朋友证号。输入格式:输入第一行给出正整数 N。随后一行给出 N 个正整数,数字间以空格分隔。题目保证所有数字小于104。输出格式:首...原创 2018-08-27 00:39:52 · 264 阅读 · 0 评论 -
1029 Median (25 分)PAT (Advanced Level) Practice
1029 Median (25 分)Given 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,...原创 2018-10-10 20:16:36 · 181 阅读 · 0 评论 -
1007. Maximum Subsequence Sum (25)-PAT甲级真题(最大连续子序列和、动态规划dp)
1007 Maximum Subsequence Sum (25 分)Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1≤i≤j≤K. The Maximum Su...原创 2018-09-30 01:21:22 · 312 阅读 · 0 评论 -
1053 Path of Equal Weight (30 分)PAT (Advanced Level) Practice
1053 Path of Equal Weight (30 分)Given 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 o...原创 2018-10-18 18:04:53 · 166 阅读 · 0 评论 -
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...原创 2018-10-15 20:45:57 · 422 阅读 · 0 评论 -
1003. Emergency (25)-PAT甲级真题(Dijkstra算法)
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...原创 2018-09-29 21:08:57 · 372 阅读 · 0 评论 -
1040 Longest Symmetric String (25 分)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, hence you ...原创 2018-10-14 18:05:38 · 242 阅读 · 0 评论 -
1039 Course List for Student (25 分)stl的容器套容器
1039 Course 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 co...原创 2018-10-14 17:38:00 · 157 阅读 · 0 评论 -
1038 Recover the Smallest Number (30 分)PAT (Advanced Level) Practice
1038 Recover the Smallest Number (30 分)Given 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 recove...原创 2018-10-14 16:24:48 · 195 阅读 · 0 评论 -
1023 Have Fun with Numbers (20 分)PAT (Advanced Level) Practice
1023 Have 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 happe...原创 2018-10-08 09:43:24 · 213 阅读 · 0 评论 -
1021 Deepest Root (25 分)PAT (Advanced Level) Practice
1021 Deepest Root (25 分)A graph which is connected and acyclic can be considered a tree. The hight of the tree depends on the selected root. Now you are supposed to find the root that results in a h...原创 2018-10-08 00:41:47 · 160 阅读 · 0 评论 -
1049 Counting Ones (30 分)
The task is simple: given any positive integer N, you are supposed to count the total number of 1's in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1's i...原创 2018-10-16 00:30:43 · 638 阅读 · 1 评论 -
1050 String Subtraction (20 分)
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1−S2 for any given s...原创 2018-10-16 00:52:09 · 123 阅读 · 0 评论 -
PAT-2019年春季-甲级
7-3Telefraud Detection(25分)Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are ...转载 2019-03-22 23:21:37 · 543 阅读 · 0 评论 -
PAT-2019甲级
7-2Anniversary(25分)Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebration, the alumni association (校友会) has gathered the ID's of all her alumni. N...原创 2019-03-22 21:00:33 · 306 阅读 · 0 评论 -
1086. Tree Traversals Again (树的遍历,前序中序转后序)
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 stac...原创 2018-11-03 12:43:59 · 426 阅读 · 0 评论 -
1085. Perfect Sequence (25)-PAT甲级真题
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...原创 2018-11-03 10:48:42 · 194 阅读 · 0 评论 -
1057 Stack (30 分)PAT (Advanced Level) Practice
Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top position) and Po...原创 2018-10-22 02:23:25 · 186 阅读 · 0 评论 -
1064 Complete Binary Search Tree (30 分)PAT (Advanced Level) Practice
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 less than the node's key. The right su...原创 2018-10-22 01:07:38 · 188 阅读 · 0 评论 -
1030 Travel Plan (30 分)PAT (Advanced Level) Practice
1030 Travel 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 d...原创 2018-10-10 21:16:29 · 175 阅读 · 0 评论 -
1025 PAT Ranking (25 分)PAT (Advanced Level) Practice
1025 PAT 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 pl...原创 2018-10-10 18:41:15 · 176 阅读 · 0 评论 -
1055 The World's Richest (25 分)PAT (Advanced Level) Practice
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the peopl...原创 2018-10-19 20:20:01 · 214 阅读 · 0 评论 -
1047 Student List for Course (25 分)
Zhejiang 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 S...原创 2018-10-17 23:52:00 · 257 阅读 · 0 评论 -
1018 Public Bike Management (30 分)PAT (Advanced Level) Practice
1018 Public Bike Management (30 分)There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and ret...原创 2018-10-07 00:37:53 · 209 阅读 · 0 评论 -
1012 数字分类
给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字: A1 = 能被 5 整除的数字中所有偶数的和;A2 = 将被 5 除后余 1 的数字按给出顺序进行交错求和,即计算 n1−n2+n3−n4⋯;A3 = 被 5 除后余 2 的数字的个数; A4 = 被 5 除后余 3 的数字的平均数,精确到小数点后 1 位;...原创 2018-09-05 00:22:14 · 171 阅读 · 0 评论 -
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 行给出:第...原创 2018-09-02 00:15:09 · 205 阅读 · 0 评论 -
1073. 多选题常见计分法
批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 50% 分数;如果考生选择了任何一个错误的选项,则不能得分。本题就请你写个程序帮助老师批改多选题,并且指出哪道题的哪个选项错的人最多。输入格式:输入在第一行给出两个正整数 N(≤1000)和 M(≤100),分别是学生人数和多选题的个数。随后 M 行,每...原创 2018-09-01 21:49:00 · 634 阅读 · 2 评论 -
1010 一元多项式求导
设计函数求一元多项式的导数。(注:xn(n为整数)的一阶导数为nxn−1。)输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过 1000 的整数)。数字间以空格分隔。输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是 0,但是表示为 0 0。输入样例:3 4 ...原创 2018-09-04 15:31:00 · 416 阅读 · 0 评论 -
1009 说反话
给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过 80 的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用 1 个空格分开,输入保证句子末尾没有多余的空格。输出格式:每个测试用例的输出占一行,输出倒序后的句子。输入样例:Hello World Her...原创 2018-09-04 15:17:50 · 159 阅读 · 0 评论 -
1008 数组元素循环右移问题
一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A0A1⋯AN−1)变换为(AN−M⋯AN−1A0A1⋯AN−M−1)(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?输入格式:每个输入包含一个测试用例,第1行输入N...原创 2018-09-04 15:07:09 · 199 阅读 · 0 评论 -
1007 素数对猜想
让我们定义dn为:dn=pn+1−pn,其中pi是第i个素数。显然有d1=1,且对于n>1有dn是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。现给定任意正整数N(<105),请计算不超过N的满足猜想的素数对的个数。输入格式:输入在一行给出正整数N。输出格式:在一行中输出不超过N的满足猜想的素数对的个数。...原创 2018-09-04 14:51:28 · 237 阅读 · 0 评论 -
1006 换个格式输出整数
让我们用字母 B 来表示“百”、字母 S 表示“十”,用 12...n 来表示不为零的个位数字 n(<10),换个格式来输出任一个不超过 3 位的正整数。例如 234 应该被输出为 BBSSS1234,因为它有 2 个“百”、3 个“十”、以及个位的 4。输入格式:每个测试输入包含 1 个测试用例,给出正整数 n(<1000)。输出格式:每个测试用例的输出占一行,用规定...原创 2018-09-04 14:45:21 · 143 阅读 · 0 评论 -
1080 MOOC期终成绩
对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分(满分100)。总评成绩的计算公式为 G=(Gmid−term×40%+Gfinal×60%),如果 Gmid−term>Gfinal;否则总评 G 就是 Gfinal...原创 2018-09-01 00:35:56 · 888 阅读 · 0 评论 -
1085 PAT单位排行
每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜。本题就请你实现这个功能。输入格式:输入第一行给出一个正整数 N(≤105),即考生人数。随后 N 行,每行按下列格式给出一个考生的信息:准考证号 得分 学校其中准考证号是由 6 个字符组成的字符串,其首字母表示考试的级别:B代表乙级,A代表甲级,T代表顶级;得分是 [0, 100] 区间内的整数;学校是由不超过...原创 2018-08-31 16:05:27 · 378 阅读 · 0 评论 -
1078 字符串压缩与解压
文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示。例如 ccccc 就用 5c 来表示。如果字符没有重复,就原样输出。例如 aba 压缩后仍然是 aba。解压方法就是反过来,把形如 5c 这样的表示恢复为 ccccc。本题需要你根据压缩或解压的要求,对给定字符串进行处理。这里我们简单地假设原始字符串是完全由英文字母...原创 2018-08-30 18:04:31 · 219 阅读 · 0 评论 -
1013 数素数
令 Pi 表示第 i 个素数。现任给两个正整数 M≤N≤104,请输出 PM 到 PN 的所有素数。输入格式:输入在一行中给出 M 和 N,其间以空格分隔。输出格式:输出从 PM 到 PN 的所有素数,每 10 个数字占 1 行,其间以空格分隔,但行末不得有多余空格。输入样例:5 27输出样例:11 13 17 19 23 ...原创 2018-09-05 00:39:44 · 260 阅读 · 0 评论
分享