![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法学习
文章平均质量分 85
我们都曾拥有最美的时光
https://github.com/Soulghost
展开
-
1090. Highest Price in Supply Chain (25) -计层的BFS改进
题目如下:A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier,原创 2015-08-24 18:24:04 · 950 阅读 · 0 评论 -
1047. Student List for Course (25)
题目如下:Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the course原创 2015-07-18 10:26:17 · 558 阅读 · 0 评论 -
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 decide the sh原创 2015-08-25 19:14:09 · 1461 阅读 · 0 评论 -
1086. Tree Traversals Again (25)
题目如下: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 traver原创 2015-08-12 14:02:54 · 3392 阅读 · 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 a原创 2015-07-19 12:22:40 · 1421 阅读 · 0 评论 -
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 stri原创 2015-07-20 13:47:38 · 1032 阅读 · 0 评论 -
1051. 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原创 2015-07-20 13:50:55 · 3076 阅读 · 3 评论 -
1064. Complete Binary Search Tree (30)
题目如下: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 k原创 2015-07-31 23:58:56 · 1997 阅读 · 0 评论 -
1089. Insert or Merge (25)
题目如下:According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from原创 2015-08-13 12:14:18 · 1610 阅读 · 0 评论 -
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 structur原创 2015-07-21 19:44:30 · 625 阅读 · 0 评论 -
1083. List Grades (25)
题目如下:Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of whic原创 2015-08-11 14:17:01 · 698 阅读 · 0 评论 -
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 Now given a sequence and a parameter p, you are supposed to原创 2015-08-11 14:27:05 · 2282 阅读 · 0 评论 -
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 st原创 2015-07-28 15:14:11 · 572 阅读 · 0 评论 -
1076. Forwards on Weibo (30) - 记录层的BFS改进
题目如下:Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relat原创 2015-08-23 22:42:46 · 946 阅读 · 0 评论 -
1045. Favorite Color Stripe (30) -LCS允许元素重复
题目如下: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 re原创 2015-07-16 13:10:03 · 2230 阅读 · 0 评论 -
1079. Total Sales of Supply Chain (25) -记录层的BFS改进
题目如下:A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier,原创 2015-08-23 22:57:03 · 1109 阅读 · 0 评论 -
1062. Talent and Virtue (25)
题目如下:About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both ta原创 2015-07-29 14:31:50 · 606 阅读 · 0 评论 -
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原创 2015-07-17 11:10:37 · 1788 阅读 · 1 评论 -
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原创 2015-08-10 17:56:30 · 1263 阅读 · 0 评论 -
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 payme原创 2015-07-18 10:33:40 · 986 阅读 · 0 评论 -
1063. Set Similarity (25)
题目如下:Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of原创 2015-07-30 10:09:32 · 795 阅读 · 0 评论 -
1066. Root of AVL Tree (25)
题目要求从一棵空二叉树树开始插入不多于20个结点,在插入过程中保证二叉树为AVL树(一种自平衡二叉查找树),在最后输出AVL树的根结点。根据概念,调平衡共有四种情况,分别是左单旋LL,右单旋RR,左右双旋LR以及右左双旋RL。Ⅰ在讨论旋转算法之前,先用链式存储方式构建二叉树存储结点,这里除了结点处的值、左右子树地址之外,还应该有一个字段用来存储该结点的子树最大高度。原创 2014-12-26 14:12:02 · 649 阅读 · 0 评论 -
1091. Acute Stroke (30)
题目如下:One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, you原创 2015-08-28 14:30:56 · 1534 阅读 · 0 评论 -
1081. Rational Sum (20) -最大公约数
题目如下:Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts原创 2015-08-17 19:10:37 · 781 阅读 · 0 评论 -
1071. Speech Patterns (25)
题目要求从一个自然段(一行句子,包含特殊字符)中找出出现频率最高的单词,注意这里的单词定义,连续的字符数字序列,数字也是合法的。要做出此题目,可以使用getline读取一行句子,然后遍历过程中用stringstream接收字符,在处理完一个单词后输出,再用map记录单词的出现频率。注意点:①stringstream输出字符串使用ss.str()。②清空stringstream不要用ss.clear,应该用ss.str("")。原创 2015-08-05 13:38:48 · 1329 阅读 · 0 评论 -
1072. Gas Station (30)
题目如下: 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原创 2015-08-06 15:22:38 · 1136 阅读 · 2 评论 -
1096. Consecutive Factors (20)
题目如下:Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive number原创 2015-08-18 19:15:25 · 3366 阅读 · 2 评论 -
对LCS算法及其变种的初步研究
LCS的全称为Longest Common Subsequence,用于查找两个字符串中的最大公共子序列,这里需要注意区分子序列与子串,所谓子序列,指的是从前到后,可以跳跃元素筛选,而字串则必须连续筛选。例如AB##!C!@#E和AB123CC321E两个字符串,如果找最长公共字串,只能是AB;如果是找最长公共子列,则是ABCE。还有一种变种的LCS,允许元素重复,这样找到的子列将会是AB原创 2015-09-09 16:00:34 · 673 阅读 · 0 评论 -
1073. Scientific Notation (20)
题目要求对给定的科学计数法进行解析,并且输出传统计数法表示的数字,要求正数不带正号,小数保留原来的后缀0个数。这个题的关键是结合string的find、substr方法查找和截取,使用stringstream来转换字符串到数字。此类问题最主要的是抓住分类讨论的要点,处理尽可能少的情况。原创 2015-08-07 12:47:41 · 1423 阅读 · 0 评论 -
1077. Kuchiguse (20)
题目如下:The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preferen原创 2015-08-20 18:10:30 · 1510 阅读 · 0 评论 -
1101. Quick Sort (25)
题目要求找出序列中的所有x,使得x满足≥前面所有的数,≤后面所有的数,这样的x称为快排中的主元。为了快速的判断,显然我们需要x左侧的最大值和右侧的最小值,而且他们一直在变动,一个思路是用两个vector或者数组记录每个位置之前最大值、之后最小值,称为maxBefore和minBehind,它们的实现逻辑如下:①第一个元素没有左侧元素,因此maxBefore[0]=-1作为初始化条件,这样就保证了必然满足。②最后一个元素没有右侧元素,因此minBehind[N-1]=INF(注意INF>10的9次方)。原创 2015-09-14 13:29:16 · 1046 阅读 · 0 评论 -
1100. Mars Numbers (20)
这道题来自2015年9月12号刚考完的PAT甲级考试第一题,本人表示被虐成狗T T,第一次考试就碰到这种坑题。好了不吐槽了,来说一下这道题的正确做法。首先最重要的是第一句,火星上的人以13进制计数,因此如果要将数字转化为火星进制,首先要进行除13取余法进制转换,例如样例中的29在13进制下为23,然后再拿高位和低位分别去查表。最容易犯的错误是13的整倍数输出问题,例如39,应该输出maa而不是maa tret。原创 2015-09-13 21:07:51 · 1508 阅读 · 0 评论 -
1084. Broken Keyboard (20)
题目如下:On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you原创 2015-08-17 19:14:56 · 846 阅读 · 0 评论 -
1070. Mooncake (25)
题目如下:Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the region's原创 2015-08-04 12:19:58 · 1032 阅读 · 0 评论 -
1080. Graduate Admission (30)
题目如下:It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate原创 2015-08-28 15:31:01 · 1031 阅读 · 0 评论 -
1067. Sort with Swap(0,*) (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原创 2015-08-02 20:09:16 · 1417 阅读 · 0 评论 -
1068. Find More Coins (30)
题目如下: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 payment原创 2015-08-03 14:10:02 · 3708 阅读 · 2 评论 -
1074. Reversing Linked List (25)
题目如下:Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K = 3, then you must output 3→2→1原创 2015-08-14 14:16:45 · 1542 阅读 · 0 评论 -
1095. Cars on Campus (30)
题目如下:Zhejiang University has 6 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 ava原创 2015-08-27 16:30:15 · 2766 阅读 · 0 评论 -
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 assign原创 2015-08-29 11:27:36 · 1264 阅读 · 0 评论