数据结构与算法
文章平均质量分 92
安河桥北Chester
Welcome to Seb's.
展开
-
【通过PAT复习C++与数据结构】PAT-A 1144 The Missing Number (20 分)
题目Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.Input Specification:Each input file contains one test case. For each case, the first line gi...原创 2019-08-28 02:05:03 · 142 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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, ...原创 2019-08-15 10:21:51 · 265 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 1020 Tree Traversals (25 分)
题目Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the ...原创 2019-08-19 20:33:23 · 180 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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...原创 2019-08-10 11:36:28 · 126 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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 produc...原创 2019-08-14 10:51:32 · 120 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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. Howev...原创 2019-08-14 09:01:54 · 173 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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 ...原创 2019-08-06 16:07:09 · 138 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT B1020 完美数列
题目描述题目描述给定一个正整数数列,和正整数p,设这个数列中的最大值是M,最小值是m,如果M <= m * p,则称这个数列是完美数列。现在给定参数p和一些正整数,请你从中选择尽可能多的数构成一个完美数列。输入描述:输入第一行给出两个正整数N和p,其中N(<= 105)是输入的正整数的个数,p(<= 109)是给定的参数。第二行给出N个正整数,每个数不超过109。输...原创 2019-03-04 18:23:59 · 341 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】刷PAT及其他算法题笔记(持续更新中)
在大整数运算、比大小中,用long double有奇效,比龙long long好得多,能满足2^64位精度运算需求(大概是10 ^19)。但是要注意,如果用scanf输入要%llf在输出时钟时间的时候常常要求格式化输出为03:05这样,可以用%02d...原创 2019-07-06 16:43:41 · 286 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 1065. A+B and C (64bit) (20)
题目描述题目描述Given three integers A, B and C in [-263, 263), you are supposed to tell whether A+B > C.输入描述:The first line of the input gives the positive number of test cases, T (<=1000). Then T...原创 2019-07-06 16:29:59 · 325 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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.输入描述:Each input file contains one t...原创 2019-07-06 15:38:35 · 117 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 1152 Google Recruitment (20 分)
题目In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below) for recruitment. The content is super-simple, a URL consisting of the first 10-digi...原创 2019-08-24 21:05:18 · 1247 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 1001 A+B Format (20 分)
题目Calculate a+b and 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-08-22 21:48:00 · 134 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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 in each city and th...原创 2019-08-22 20:43:50 · 297 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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 g...原创 2019-08-16 21:47:38 · 99 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】关于DFS入门的理解 (PATA1013 Battle Over Cities (25 分)等题目)
第一次刷到DFS的算法题被卡住了,DFS不是那么容易理解,它在直观上很容易看出算法过程,但是在解题的时候很抽象,于是就看了很多的博客以及书,慢慢的有了一个理解。其实DFS本质上就是暴力,适用于从数据中排列组合,找出所有的组合可能性,然后根据题目要求判断的题型。很多博客都给出了DFS模板,其实我觉得理解了dfs过程后,模板并没有多大用处。理解dfs关键在于理解两点:DFS本质是找出所有的...原创 2019-08-22 03:09:24 · 154 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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 examp...原创 2019-08-16 20:05:13 · 343 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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 s...原创 2019-08-21 20:02:43 · 129 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 1155 Heap Paths (30 分)
题目In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to...原创 2019-08-25 21:25:00 · 149 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 1154 Vertex Coloring (25 分)
题目A proper vertex coloring is a labeling of the graph’s vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper...原创 2019-08-25 20:12:21 · 200 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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 sequence of ...原创 2019-08-16 10:17:17 · 108 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT A1031 Shuffling Machine (20)
题目题目描述Shuffling is a procedure used to randomize a deck of playing cards.Because standard shuffling techniques are seen as weak, and in order toavoid “inside jobs” where employees collaborate with...原创 2019-07-06 01:35:08 · 105 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A Spell It Right (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 ...原创 2019-07-15 14:10:51 · 529 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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.输入描述:Each input file contains one test case. Each case occupie...原创 2019-07-13 00:17:24 · 154 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】1016. 部分A+B (15)-PAT乙级真题
题目正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA。例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6。现给定A、DA、B、DB,请编写程序计算PA + PB。输入格式:输入在一行中依次给出A、DA、B、DB,中间以空格分隔,其中0 < A, B < 10^10。输出格式:在一行中输出PA + PB的值。...原创 2019-04-22 21:08:57 · 127 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-B1010 月饼 (25) ——贪心算法入门
题目描述月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有3种月饼,其库存量分别为18、15、10万吨,总售价分别为75、72、45亿元。如果市场的最大需求量只有20万吨,那么我们最大收益策略应该是卖出全部15万...原创 2019-04-17 15:34:55 · 192 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A.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 places, and the ranklist...原创 2019-04-14 16:13:18 · 172 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-B 1015. 德才论 (25)-PAT乙级真题
虽然这是一道乙级真题,但是做了我好久才做对,回头看了柳婼柳神的代码,更加意识到了对知识灵活运用的重要性。题目题目描述:宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”现给出一批考生的德才分数,请根据司马光的理论给出录取排名。输入格式:输入第1行...原创 2019-04-21 21:30:41 · 260 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT B1008.锤子剪刀布
题目描述大家应该都会玩“锤子剪刀布”的游戏:现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。输入描述:输入第1行给出正整数N(&lt;=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。输出描述:输出第1、...原创 2019-03-04 17:28:26 · 324 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT B1036.和奥巴马一起编程
今天刷的是图形输出题题目链接:https://www.nowcoder.com/questionTerminal/8af708723b0f45f9a80bc80d78d3566e来源:牛客网题目美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一...原创 2019-02-28 21:51:49 · 173 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】 Codeup 1934 找x
题外话春节懒了好久,刷题中断了,罪恶啊!今天开始继续刷题,然后分按照题目分类来刷,相同类型的题目集中刷,能够方便归纳总结。共勉。第一题 【Codeup 1934】找x题目描述输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数组中则输出-1)。输入测试数据有多组,输入n(1<=n<=200),接着输入n个数,然后输入x。...原创 2019-02-28 19:41:29 · 148 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-B 1003.数素数
题目题目描述令Pi表示第i个素数。现任给两个正整数M &lt;= N &lt;= 10000,请输出PM到PN的所有素数。输入描述:输入在一行中给出M和N,其间以空格分隔。输出描述:输出从PM到PN的所有素数,每10个数字占1行,其间以空格分隔,但行末不得有多余空格。输入例子:5 27输出例子:11 13 17 19 23 29 31 37 41 4347 ...原创 2019-01-08 18:49:03 · 127 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-B 1002.数字分类
题目题目描述给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字:A1 = 能被5整除的数字中所有偶数的和;A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4…;A3 = 被5除后余2的数字的个数;A4 = 被5除后余3的数字的平均数,精确到小数点后1位;A5 = 被5除后余4的数字中最大数字。输入描述:每个输入包含1个测试用例。每个...原创 2019-01-08 17:35:18 · 139 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-B 1001. A+B和C
题目给定区间[-2^31, 2^31]内的3个整数A、B和C,请判断A+B是否大于C。输入格式:输入第1行给出正整数T(&amp;lt;=10),是测试用例的个数。随后给出T组测试用例,每组占一行,顺序给出A、B和C。整数间以空格分隔。输出格式:对每组测试用例,在一行中输出“Case #X: true”如果A+B&amp;gt;C,否则输出“Case #X: false”,其中X是测试用例的编号(从1开...原创 2019-01-08 15:39:45 · 197 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-B 1013 组个最小数 (20)——贪心策略
题目描述给定数字0-9各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意0不能做首位)。例如:给定两个0,两个1,三个5,一个8,我们得到的最小的数就是10015558。现给定数字,请编写程序输出能够组成的最小的数。输入输出输入描述:每个输入包含1个测试用例。每个测试用例在一行中给出10个非负整数,顺序表示我们拥有数字0、数字1、……数字9的个...原创 2019-04-18 14:37:37 · 135 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-B 1030 有几个PAT(25)
题目描述字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位§,第4位(A),第6位(T);第二个PAT是第3位§,第4位(A),第6位(T)。现给定字符串,问一共可以形成多少个PAT?输入输出输入描述:输入只有一行,包含一个字符串,长度不超过105,只包含P、A、T三种字母。输出描述:在一行中输出给定字符串中包含多少个PAT。由于结果可能比较大,只输出对10000...原创 2019-04-18 16:01:36 · 162 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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.输入描述:Each input file contains one test case. Eac...原创 2019-07-09 00:38:42 · 176 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A A+B for Polynomials (25)
题目This time, you are supposed to find A+B where A and B are two polynomials.输入描述:Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a poly...原创 2019-07-07 23:00:27 · 501 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT刷题过程中单词记录(持续更新)
英文中文accurate up to 2 decimal places精确到两位小数原创 2019-07-07 17:03:11 · 340 阅读 · 0 评论 -
【通过PAT复习C++与数据结构】PAT-A 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....原创 2019-07-07 16:55:38 · 173 阅读 · 0 评论