
algorithm
wwang_dev
人生苦短,我学java!
展开
-
PAT 1052 Linked List Sorting (25分) 结构体排序而已
题目A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, you are supposed to sort the structu原创 2020-07-04 08:32:37 · 205 阅读 · 0 评论 -
PAT1051 Pop Sequence (25分) 模拟入栈
题目Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obt原创 2020-07-03 21:32:13 · 184 阅读 · 0 评论 -
PAT1050 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 strings. However, it might not be that simple原创 2020-07-03 19:23:57 · 174 阅读 · 0 评论 -
PAT 1049 Counting Ones (30分) 编程之美--1的个数
题目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 in 1, 10, 11, and 12.Input Specification:Each input原创 2020-07-03 17:31:15 · 209 阅读 · 0 评论 -
PAT 1048 Find Coins (25分) 硬币面值做数组下标即排序
题目Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special requirement of the payment: for原创 2020-07-03 11:22:58 · 2684 阅读 · 0 评论 -
PAT1047 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 Specification:Each input file contains one test case.原创 2020-07-03 08:46:59 · 1198 阅读 · 0 评论 -
PAT 1046 Shortest Distance (20分)
题目The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specification:Each input file contains one test case. For each case, the first line contai原创 2020-07-02 22:06:05 · 128 阅读 · 0 评论 -
PAT1045 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 together to form her favorite color stripe.It is sa原创 2020-07-02 19:12:29 · 178 阅读 · 0 评论 -
PAT 1044 Shopping in Mars (25分) 二分法
题目Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some of the diamonds are taken off原创 2020-07-02 10:40:57 · 223 阅读 · 0 评论 -
PAT 1043 Is It a Binary Search Tree (25分) 由前序遍历得到二叉搜索树的后序遍历
题目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 subtree of a node contains only nodes with keys greater原创 2020-06-14 18:42:35 · 248 阅读 · 1 评论 -
PAT1042 Shuffling Machine (20分) 用1-54代替点数更方便哦
题目Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where employees collaborate with gamblers by performing inadequate shuffles, many casinos emp原创 2020-06-11 15:34:37 · 134 阅读 · 0 评论 -
PAT 1041 Be Unique (20分)利用数组找出只出现一次的数字
题目Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,104 ]. The first one who bets on a unique number wins. For example, if there are 7 pe原创 2020-06-11 13:26:52 · 170 阅读 · 0 评论 -
PAT1040 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 must output 11.Input Specification:Each input file原创 2020-06-10 23:13:05 · 141 阅读 · 0 评论 -
PAT 1039 Course List for Student (25分) 使用map(string, vector(int))
题目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 course list for each student who comes for a query.Input Specification:Each input file con原创 2020-06-10 22:37:30 · 229 阅读 · 0 评论 -
PAT 1038 Recover the Smallest Number (30分) string巧排序
题目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原创 2020-06-10 21:23:27 · 115 阅读 · 0 评论 -
PAT 1037 Magic Coupon (25分) 贪心+排序+负负/正正得正
题目The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the value of that product back! What is more, the shop also offers some bonus pr原创 2020-06-10 16:34:05 · 167 阅读 · 0 评论 -
PAT 1036 Boys vs Girls (25分) 比大小而已
题目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 test case. Each case contains a positive integer N, foll原创 2020-06-02 16:36:33 · 559 阅读 · 0 评论 -
PAT 1035 Password (20分) 字符替换
题目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 distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). O原创 2020-06-01 13:53:25 · 142 阅读 · 0 评论 -
PAT 1034 Head of a Gang (30分) 图的连通分量 + DFS
题目One way that the police finds the head of a gang is to check people’s phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be the total time length of all the phone calls made betw原创 2020-05-31 13:25:14 · 243 阅读 · 0 评论 -
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原创 2020-05-30 16:51:55 · 263 阅读 · 0 评论 -
PAT 1032 Sharing (25分) 从自信到自闭
题目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, loading and being are stored as showed in Figure 1.原创 2020-05-28 18:41:30 · 208 阅读 · 1 评论 -
PAT 1031 Hello World for U (20分) 找规律按行输出即可
题目Given any string of N (≥5) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as:h de ll rlowoThat is, the characters must be printed in the original order, starting top-down from the le原创 2020-05-28 13:23:02 · 185 阅读 · 0 评论 -
PAT 1030 Travel Plan (30分) Dijstra +Dfs
题目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 decide the shortest path between his/her starting city and the destination. If原创 2020-05-27 18:10:13 · 164 阅读 · 0 评论 -
PAT 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, 10, 15, 16, 17 } is 15. The median of two sequences is defined to be the原创 2020-05-27 13:18:25 · 162 阅读 · 0 评论 -
PAT 1016 Phone Bills (25分) 逻辑较为复杂 sort() + map
题目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, th原创 2020-05-19 16:46:02 · 280 阅读 · 0 评论 -
PAT 1015 Reversible Primes (20分) 谜一般的题目,不就是个进制转换+素数判断
题目A reversible prime in any number system is a prime whose “reverse” in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.Now given any two positive integers N (<105原创 2020-05-19 15:52:33 · 287 阅读 · 0 评论 -
PAT 1012 The Best Rank (25分) sort()排序就完了
题目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 emph原创 2020-05-19 15:22:03 · 225 阅读 · 1 评论 -
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 mon原创 2020-05-19 13:51:39 · 196 阅读 · 0 评论 -
PAT 1010 Radix (25分) 自己确定radix取值范围,二分法提高效率
题目Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number.Now for any pair of positive integers N1 and N2 , your task is to find the radix原创 2020-05-18 23:20:54 · 189 阅读 · 0 评论 -
PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值
题目This time, you are supposed to find A×B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2原创 2020-05-18 22:32:57 · 206 阅读 · 0 评论 -
PAT 1008 Elevator (20分) 加减法难度级别
题目The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds原创 2020-05-18 21:43:48 · 1439 阅读 · 0 评论 -
PAT 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 Subsequence is the continuous subsequence which has the largest sum of its elements. For ex原创 2020-05-18 21:29:26 · 165 阅读 · 0 评论 -
PAT 1028 List Sorting (25分) 用char[],不要用string
题目Excel can sort records according to any column. Now you are supposed to imitate this function.Input Specification:Each input file contains one test case. For each case, the first line contains two integers N (≤105 ) and C, where N is the number of re原创 2020-05-18 20:23:56 · 143 阅读 · 0 评论 -
PAT 1006 Sign In and Sign Out (25分) 字符串比较
题目At 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 are supposed to find the ones who have unlocked and原创 2020-05-18 18:26:29 · 162 阅读 · 0 评论 -
PAT 1005 Spell It Right (20分) 字符数组做映射
题目Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file contains one test case. Each case occupies one line which contains an N (≤10100).原创 2020-05-18 18:13:20 · 141 阅读 · 0 评论 -
PAT 1004 Counting Leaves (30分) dfs求每层叶子节点数
题目A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one test case. Each case starts with a line containing 0<N<100, the number of no原创 2020-05-18 18:02:11 · 1765 阅读 · 0 评论 -
PAT1003 Emergency (25分) Dijstra
题目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 mar原创 2020-05-18 17:27:03 · 142 阅读 · 0 评论 -
PAT 1002 A+B for Polynomials (25分) 指数做数组下标,系数做值
题目This time, you are supposed to find A+B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2原创 2020-05-18 15:58:50 · 260 阅读 · 0 评论 -
PAT 1027 Colors in Mars (20分) 10进制转13进制
题目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 for Red, the middle 2 digits for Green, and the last 2 digits for Blue. The on原创 2020-05-18 13:46:34 · 141 阅读 · 0 评论 -
PAT 1026 Table Tennis (30分) 难度不高 + 逻辑复杂 +细节繁琐
题目A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open when they arrive, they will be assigned to the available table with the smallest number. If all the tab原创 2020-05-17 17:26:22 · 406 阅读 · 0 评论