PAT
Xiao2018428
这个作者很懒,什么都没留下…
展开
-
PAT甲级思路速览1044—1048
1044Shopping in Mars令Sum[i]表示A[1]到A[i]的和值,因此Sum[i]是单调递增的。初始化Sum[0]=0,如果要求子序列A[i]到A[j]的和值,只需计算Sum[j]-Sum[i-1]即可。我们可以用二分法来做这道题。假设需要在序列A[1]~A[n]中寻找和值为S的连续子序列,就可以枚举左端点i(1<=i<=n),然后在Sum数组的[i,n]范围内...原创 2019-12-04 16:51:02 · 164 阅读 · 0 评论 -
PAT甲级思路速览1037——1043
1037Magic Coupon在接收两个数组数据的时候,分别统计两个数组中包含的正数和负数的个数。接收完数据之后对两个数组用sort进行排序,比较两个数组中的正数个数,取最小值b。同理,取负数个数的最小值c。这样,我们只需将排序后的两个数组中的前面b个负数对应相乘,并将结果加起来,再将两个数组后面的c个正数对应相乘,继续把结果相加就可以得到最后的输出结果。1038Recover t...原创 2019-12-03 20:10:08 · 241 阅读 · 0 评论 -
PAT甲级—— Boys vs Girls
This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.Input Specification:Each input file contains one t...原创 2019-12-02 22:52:36 · 199 阅读 · 0 评论 -
PAT甲级——Password
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish1(one) froml(L...原创 2019-12-02 11:02:54 · 142 阅读 · 0 评论 -
PAT甲级——sharing
To 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,...原创 2019-08-26 10:13:55 · 198 阅读 · 0 评论 -
PAT甲级——Hello World for U
Given any string ofN(≥5) characters, you are asked to form the characters into the shape ofU. For example,helloworldcan be printed as:h de ll rlowoThat is, the characters must be prin...原创 2019-11-26 10:28:22 · 135 阅读 · 0 评论 -
PAT甲级——Colors in Mars
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are forRed, the middle 2 dig...原创 2019-11-22 11:04:05 · 118 阅读 · 0 评论 -
PAT甲级——Palindromic Number
A number that will be the same when it is written forwards or backwards is known as aPalindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers...原创 2019-08-18 17:07:46 · 242 阅读 · 0 评论 -
PAT甲级——General Palindromic Number
A number that will be the same when it is written forwards or backwards is known as aPalindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers...原创 2019-11-18 16:16:19 · 121 阅读 · 0 评论 -
PAT甲级——Queueing at Bank
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...原创 2019-11-15 10:54:52 · 118 阅读 · 0 评论 -
PAT甲级——Phone Bills
题目描述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...原创 2019-11-13 15:57:21 · 152 阅读 · 0 评论 -
PAT甲级—— Waiting in Line
Suppose a bank hasNwindows 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...原创 2019-11-12 19:47:47 · 171 阅读 · 0 评论 -
PAT甲级—— World Cup Betting
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. Si...原创 2019-11-10 13:40:56 · 165 阅读 · 0 评论 -
PAT甲级——Product of Polynomials
his 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 informat...原创 2019-11-09 10:36:05 · 158 阅读 · 0 评论 -
PAT甲级—— Sign In and Sign Out
t the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you ...原创 2019-11-07 15:29:25 · 143 阅读 · 0 评论 -
PAT甲级——Spell It Right
Given a non-negative integerN, your task is to compute the sum of all the digits ofN, and output every digit of the sum in English.Input Specification:Each input file contains one test case. Eac...原创 2019-11-07 10:15:40 · 169 阅读 · 0 评论 -
PAT甲级——A+B for Polynomials
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-10-31 15:29:23 · 207 阅读 · 0 评论 -
PAT甲级——A+B Format
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 ...原创 2019-10-30 11:09:36 · 164 阅读 · 0 评论 -
PAT甲级——Longest Symmetric String
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 ...原创 2019-10-29 10:42:57 · 121 阅读 · 0 评论 -
PAT甲级——Favorite Color Stripe(最长不下降子序列问题)
最长不下降子序列问题(Longest Increasing Sequence,LIS)在一个数字序列中,找到一个最长的子序列(可以不连续),使得这个子序列是不下降(非递减)的。分析: 例如现有序列A={1,2,3,-1,-1,7,9}(下标从1开始),它的最长不下降子序列是 {1,2,3,7,9},长度为5。用枚举的方法是可以求出结果的,但是每个元素选取或者不选取有两种选择...原创 2019-10-24 11:03:42 · 241 阅读 · 0 评论 -
PAT甲级——1007 Maximum Subsequence Sum
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...原创 2019-10-23 10:46:23 · 144 阅读 · 0 评论 -
PAT甲级——1087 All Roads Lead to Rome
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 ...原创 2019-10-22 10:33:07 · 145 阅读 · 0 评论 -
PAT甲级——1072 Gas Station
A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the hou...原创 2019-10-21 20:43:07 · 181 阅读 · 0 评论 -
PAT甲级——1018 Public Bike Management
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 return it to any other stations in the ...原创 2019-10-20 22:32:36 · 128 阅读 · 0 评论 -
PAT甲级——Deepest Root
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root ...原创 2019-10-17 14:57:32 · 170 阅读 · 0 评论 -
PAT甲级——Battle Over Cities
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 nee...原创 2019-10-16 15:02:26 · 111 阅读 · 0 评论 -
PAT甲级—— Insertion or Heap Sort
According to Wikipedia:Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data,...原创 2019-10-14 20:31:40 · 319 阅读 · 0 评论 -
PAT甲级——Social Clusters
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. Asocial clusteris a set of people who have some of thei...原创 2019-10-12 14:28:51 · 178 阅读 · 0 评论 -
PAT乙级——1019旧键盘(20)
题目描述旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。输入描述:输入在2行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过80个字符的串,由字母A-Z(包括大、小写)、数字0-9、以及下划线“_”(代表空格)组成。题目保证2个字符串均非空。输出描述:...原创 2019-05-13 20:19:15 · 145 阅读 · 0 评论 -
PAT乙级——1020完美数列(25)
题目描述给定一个正整数数列,和正整数p,设这个数列中的最大值是M,最小值是m,如果M <= m * p,则称这个数列是完美数列。现在给定参数p和一些正整数,请你从中选择尽可能多的数构成一个完美数列。输入描述:输入第一行给出两个正整数N和p,其中N(<= 105)是输入的正整数的个数,p(<= 109)是给定的参数。第二行给出N个正整数,每个数不超过10...原创 2019-05-13 21:04:23 · 188 阅读 · 0 评论 -
PAT乙级——1021查验身份证(15)
一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得 到值Z;最后按照以下关系对应Z值与校验码M的值: Z:0 1 2 3 4 5 6 7 8 9 10 M:1 0 X 9 8 7 6 5 4 3 2 现...原创 2019-05-14 19:33:04 · 196 阅读 · 0 评论 -
PAT乙级——1023旧键盘打字(20)
题目描述旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?输入描述:输入在2行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过10^5个字符的串。可用的字符包括字母[a-z, A-Z]、数字0-9、以及下划线“_”(代表空格)、“,”、“....原创 2019-05-21 20:18:48 · 171 阅读 · 0 评论 -
PAT乙级——NowCoder数列
题目描述NowCoder最近在研究一个数列:* F(0) = 7* F(1) = 11* F(n) = F(n-1) + F(n-2) (n≥2)他称之为NowCoder数列。请你帮忙确认一下数列中第n个数是否是3的倍数。输入描述:输入包含多组数据。每组数据包含一个整数n,(0≤n≤1000000)。输出描述:对应每一组输入有一行输出。如果F(n...翻译 2019-06-05 10:34:27 · 201 阅读 · 0 评论 -
PAT乙级——1036跟奥巴马一起编程
题目描述美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧!输入描述:输入在一行中给出正方形边长N(3<=N<=20)和组成正方形边的某种字符C,间隔一个空格。输出描述:...原创 2019-05-31 10:16:28 · 341 阅读 · 0 评论 -
PAT乙级——1037在霍格沃兹找零钱(20)
题目描述如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”现在,给定哈利应付的价钱P和他实付的钱A,你的任务是写一个程序来计算他应该被找的零钱。输入描述:输入在1行中分别给出P和A,格式为“Galleon.Sickle.Knut”,其间...原创 2019-05-31 12:06:48 · 174 阅读 · 0 评论 -
PAT乙级——养兔子
题目描述一只成熟的兔子每天能产下一胎兔子。每只小兔子的成熟期是一天。 某人领养了一只小兔子,请问第N天以后,他将会得到多少只兔子。输入描述:测试数据包括多组,每组一行,为整数n(1≤n≤90)。输出描述:对应输出第n天有几只兔子(假设没有兔子死亡现象)。输入例子:12输出例子:12#include "pch.h"#...原创 2019-06-06 09:41:59 · 274 阅读 · 0 评论 -
PAT乙级——1034有理数四则运算(20)
题目描述本题要求编写程序,计算2个有理数的和、差、积、商。输入描述:输入在一行中按照“a1/b1 a2/b2”的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分母不为0。输出描述:分别在4行中按照“有理数1 运算符 有理数2 = 结果”的格式顺序输出2个有理数的和、差、积、商。注意输出的每个有理数必须是该有理数的...翻译 2019-05-29 09:53:25 · 113 阅读 · 0 评论 -
PAT乙级——统计同成绩学生(20)
题目描述本题要求读入N名学生的成绩,将获得某一给定分数的学生人数输出。输入描述:输入在第1行给出不超过105的正整数N,即学生总人数。随后1行给出N名学生的百分制整数成绩,中间以空格分隔。最后1行给出要查询的分数个数K(不超过N的正整数),随后是K个分数,中间以空格分隔。输出描述:在一行中按查询顺序给出得分等于指定分数的学生人数,中间以空格分隔,但行末不得...原创 2019-06-03 11:03:31 · 123 阅读 · 0 评论 -
PAT乙级——1039到底买不买(20)
题目描述本题要求读入N名学生的成绩,将获得某一给定分数的学生人数输出。输入描述:输入在第1行给出不超过105的正整数N,即学生总人数。随后1行给出N名学生的百分制整数成绩,中间以空格分隔。最后1行给出要查询的分数个数K(不超过N的正整数),随后是K个分数,中间以空格分隔。输出描述:在一行中按查询顺序给出得分等于指定分数的学生人数,中间以空格分隔,但行末不得...翻译 2019-06-03 15:00:40 · 137 阅读 · 0 评论 -
PAT乙级——1040有几个PAT(20)
题目描述字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T);第二个PAT是第3位(P),第4位(A),第6位(T)。现给定字符串,问一共可以形成多少个PAT?输入描述:输入只有一行,包含一个字符串,长度不超过105,只包含P、A、T三种字母。输出描述:在一行中输出给定字符串中包含多少个PAT。由于结果...翻译 2019-06-03 16:08:42 · 101 阅读 · 0 评论