PAT甲级 1085 Perfect Sequence (25分)

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 supposed to find from the sequence as many numbers as possible to form a perfect subsequence. Input Specification: Each input file contains one test case. For each case, the first line contains two positive integers N and p, where N (≤10^5) is the number of integers in the sequence, and p (≤ 10^9 ) is the parameter. In the second line there are N positive integers, each is no greater than 10^9. ...

March 28, 2020 · 2 min

PAT甲级 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 recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different orders of combinations of these segments, and the smallest number is 0229-321-3214-32-87. Input Specification: Each input file contains one test case. Each case gives a positive integer N (≤10^4) followed by N number segments. Each segment contains a non-negative integer of no more than 8 digits. All the numbers in a line are separated by a space. ...

March 28, 2020 · 2 min

PAT甲级 1067 Sort with Swap(0, i) (25分)

Given any permutation of the numbers {0, 1, 2,…, N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may apply the swap operations in the following way: Swap(0, 1) => {4, 1, 2, 0, 3} Swap(0, 3) => {4, 1, 2, 3, 0} Swap(0, 4) => {0, 1, 2, 3, 4} Now you are asked to find the minimum number of swaps need to sort the given permutation of the first N nonnegative integers. ...

March 27, 2020 · 2 min

PAT乙级 1033 旧键盘打字 (20分)

旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在 2 行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过 10^5 个字符的串。可用的字符包括字母 [a-z, A-Z]、数字 0-9、以及下划线 _(代表空格)、,、.、-、+(代表上档键)。题目保证第 2 行输入的文字串非空。 注意:如果上档键坏掉了,那么大写的英文字母无法被打出。 输出格式: 在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。 输入样例: 7+IE. 7_This_is_a_test. 输出样例: _hs_s_a_tst 注意点 读入失效键位的时候要注意,可能没有失效的键位,即第一行为空行的情况。这时候不能用 scanf 输入,而要用 cin.getline(str, maxn) 输入字符串。 #include <iostream> #include <cstring> using namespace std; const int maxn = 100001; int main() { int hash_table[256] = {0}; char wrong[257], input[maxn]; cin.getline(wrong, 257); int len = strlen(wrong); for (int i = 0; i < len; i++) { if (wrong[i] >= 'A' && wrong[i] <= 'Z') { wrong[i] = wrong[i] - 'A' + 'a'; } hash_table[wrong[i]] = 1; } scanf("%s", input); len = strlen(input); for (int i = 0; i < len; i++) { if (input[i] >= 'A' && input[i] <= 'Z') { int low = input[i] - 'A' + 'a'; if (hash_table[low] == 0 && hash_table['+'] == 0) { printf("%c", input[i]); } } else if (hash_table[input[i]] == 0) { printf("%c", input[i]); } } printf("\n"); return 0; }

March 26, 2020 · 1 min

PAT甲级 1033 To Fill or Not to Fill (25分)

With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give different price. You are asked to carefully design the cheapest route to go. Input Specification: Each input file contains one test case. For each case, the first line contains 4 positive numbers: Cmax (≤ 100), the maximum capacity of the tank; D (≤30000), the distance between Hangzhou and the destination city; Davg (≤20), the average distance per unit gas that the car can run; and N (≤ 500), the total number of gas stations. Then N lines follow, each contains a pair of non-negative numbers: Pi, the unit gas price, and Di (≤D), the distance between this station and Hangzhou, for i=1,⋯,N. All the numbers in a line are separated by a space. ...

March 22, 2020 · 3 min

PAT甲级 1095 Cars on Campus (30分)

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 number of cars parking on campus, and at the end of the day find the cars that have parked for the longest time period. ...

March 22, 2020 · 4 min

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 a customer starts connecting a long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone. Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day). Your job is to prepare the bills for each month, given a set of phone call records. ...

March 20, 2020 · 4 min

PAT甲级 1012 The Best Rank (25分)

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student. ...

March 20, 2020 · 3 min

PAT甲级 1082 Read Number in Chinese (25分)

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 san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu. Note: zero (ling) must be handled correctly according to the Chinese tradition. For example, 100800 is yi Shi Wan ling ba Bai. ...

March 19, 2020 · 2 min

PAT甲级 1061 Dating (20分)

Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. It took him only a minute to figure out that those strange strings are actually referring to the coded time Thursday 14:04 – since the first common capital English letter (case sensitive) shared by the first two strings is the 4th capital letter D, representing the 4th day in a week; the second common character is the 5th capital letter E, representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to 9 and the capital letters from A to N, respectively); and the English letter shared by the last two strings is s at the 4th position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the dating time. ...

March 18, 2020 · 3 min