自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(132)
  • 收藏
  • 关注

原创 PAT-A 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 traversed, the stac...

2019-08-10 11:06:12 139

原创 PAT-A 1099 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 cor...

2019-08-07 13:22:32 159

原创 PAT-A 1022 1008 Elevator (20 分)

The highest building in our city has only one elevator. A request list is made up withNpositive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 sec...

2019-08-06 14:24:42 359

原创 PAT-A 1007 Maximum Subsequence Sum (25 分)

Given a sequence ofKintegers {N​1​​,N​2​​, ...,N​K​​}. A continuous subsequence is defined to be {N​i​​,N​i+1​​, ...,N​j​​} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequen...

2019-08-06 14:06:55 159

原创 PAT-A 1004 Counting Leaves (30 分)

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...

2019-08-06 12:00:32 150

原创 PAT-A 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 shortest path b...

2019-06-18 22:39:20 115

原创 PAT-A 1018 Public Bike Management (30 分)

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-06-18 22:37:11 125

原创 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 the l...

2019-06-16 23:57:29 99

原创 PAT-A 1076 Forwards on Weibo (30 分)

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 relations. When a ...

2019-06-16 00:15:10 101

原创 PAT-A 1034 Head of a Gang (30 分)

One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call betweenAandB, we say thatAandBis related. The weight of a relation is defined to be t...

2019-06-15 22:33:43 108

原创 PAT-A 1021 Deepest Root (25 分)

1021Deepest Root(25分)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 ...

2019-06-13 23:09:26 210

原创 PAT-A 1099 1013 Battle Over Cities (25 分)

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-06-11 02:23:30 153

原创 PAT-A 1107 Social Clusters (30 分)

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-06-11 01:09:03 89

原创 PAT-A 1098 Insertion or Heap Sort (25 分)

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-06-11 01:05:56 105

原创 PAT-A 1066 Root of AVL Tree (25 分)

An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is...

2019-05-24 22:50:18 105

原创 PAT-A 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 key. The right su...

2019-05-24 09:02:18 472

原创 PAT-A 1099 Build A 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 key. The right su...

2019-05-24 08:58:25 117

原创 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 su...

2019-05-22 17:43:07 78

原创 PAT-A 1097 Deduplication on a Linked List (25 分)

Given a singly linked listLwith integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each valueK, only the first node of which the value or a...

2019-04-18 19:59:55 94

原创 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 integerkeyand aNextpointer to the next structure. Now give...

2019-04-18 19:29:13 87

原创 PAT-A 1074 Reversing Linked List (25 分)

Given a constantKand a singly linked listL, you are supposed to reverse the links of everyKelements onL. For example, givenLbeing 1→2→3→4→5→6, ifK=3, then you must output 3→2→1→6→5→4; ifK=4, ...

2019-04-18 18:43:57 89

原创 PAT-A 1056 Mice and Rice (25 分)

思路:按照题目给定order依次将每个玩家加入到一个play队列中,分组进行比赛。每轮输的玩家加入到每轮各自的一个输家队列中,赢家继续留在play队列中进行比赛,直到play队列中只剩下一个玩家,该玩家即为冠军。

2019-04-17 12:52:38 197

原创 PAT-A 1032 Sharing (25 分)

思路:数据部分没有用到,因此可以将每个节点保存到map中,映射是从该节点地址到下一节点的地址。将两个单词的结点的地址依次入栈,再依次弹出,直到有一个栈为空或者弹出的值不等为止。输出的时候注意,如果不是-1要使用"%05d"进行格式化。

2019-04-17 11:06:56 135

原创 PAT-A 1054 The Dominant Color (20 分)

Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the d...

2019-04-13 14:57:27 89

原创 PAT-A 1071 Speech Patterns (25 分)

People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker...

2019-04-13 14:55:49 93

原创 PAT-A 1022 Digital Library (30 分)

思路:如果将所有的书保存到一个vector中,查询时肯定会超时。为所有的书名、作者、关键字、出版社、出版年份维护一个map,值为与该条件有关的所有书的id。坑点:书的id可能以0开头,输出的时候注意。

2019-04-13 14:53:38 102

原创 PAT-A 1100 Mars Numbers (20 分)

People on Mars count their numbers with base 13:Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earth is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, ...

2019-04-12 22:57:17 125

原创 PAT-A 1063 Set Similarity (25 分)

Given two sets of integers, the similarity of the sets is defined to beN​c​​/N​t​​×100%, whereN​c​​is the number of distinct common numbers shared by the two sets, andN​t​​is the total number of ...

2019-04-12 17:40:13 102

原创 PAT-A 1060 Are They Equal (25 分)

思路:关键是找到小数点移动的方向和距离。规律如下浮点数 小数点下标 第一个非0数的下标 指数12345 5 0 5 (5-0)123.45 3 0 3 (3-0)0.00123· 1

2019-04-12 17:37:49 1750

原创 PAT-A 1039 Course List for Student (25 分)

分析: 考虑到极限情况下内存很可能不够,因此将姓名通过字符串哈希算法映射成一个整数,由于只有3位大写英文字母,最大的数也就1万多,整型足够。

2019-04-11 22:46:28 99

原创 PAT-A 1024 Palindromic Number (25 point(s))

思路:一个数逆转后比原来的数大的概率直观上看是0.5,我认为把一个数逆转后再和原来的数加和,经过100次后,可能和原数的2^100倍接近,long long的范围为2^63-1,因此要自己写大整数运算.

2019-02-16 20:12:23 82

原创 PAT-A 1023 Have Fun with Numbers (20 point(s))

思路:20位的整数乘以2,最大是21位,long long大致范围为9*10^18,因此只能自己写大整数乘法运算,这里采用算法笔记上的大整数思路.

2019-02-16 18:08:48 137

原创 PAT-A 1096 Consecutive Factors (20 point(s))

思路:存在连乘序列时,序列中的因数小于等于sqrt(n), 分别将2~sqrt(n)作为连乘序列第一个数,计算其连乘序列长度,并记录最长序列的长度和第一个数.如果在2~sqrt(n)之间不存在n的因数,说明n为1或者为质数.此时连乘序列的最大长度为0,特判输出即可.

2019-02-09 14:42:00 139

原创 PAT-A 1059 Prime Factors (25 point(s))

思路: 对一个正数n来说,如果它存在[2, n]范围内的质因子,要么这些质因子全部小于等于sqrt(n),要么只存在一个大于sqrt(n)的质因子,这样便可以开数组利用筛法求素数表,然后遍历素数表分解质因数.

2019-02-08 22:25:21 100

原创 PAT-A 1069 The Black Hole of Numbers (20 point(s))/ PAT-B 1019 数字黑洞(20分)

思路:sprintf和sscanf的使用以及sort函数的使用。

2019-01-29 16:34:23 103

原创 PAT-A 1029 Median (25 point(s))

思路:内存限制1.5M,如果两个数组的长度都是2×10​^5,那么刚好会超出1.5M,导致卡一个点,因此第二个数组不能一次性输入后再进行计算。每输入第二个数组中的一个数字,进行判断。如果第二个数组中的数字完全输入后还是没有正确答案,那么中位数就在第一个数组中。

2019-01-29 15:43:55 235

原创 PAT-A 1101 Quick Sort (25 point(s))/ PAT-B 1045 快速排序(25分)

思路:找到每个数字前面(包括该数字)的最大值和后面(包括该数字)的最小值, 如果该数字和其前面的最大值和后面的最小值相等,该数字可以作为候选。因为题目要求在“一行”中输出所有的候选,因此最后要输出一个换行符,否则当不存在候选时,会卡一个点。

2019-01-25 14:03:39 137

原创 PAT-A 1093 Count PAT's (25 point(s))/ PAT-B 1040 有几个PAT(25)

思路:遍历输入的串,如果是A,用A前面的P的数量乘以A后面的T的数量就是当前这个A可以构造的PAT的数量。为了快速得到A后面的T的数量,先遍历一遍字符串, 计算字符串中所有T的数量。这样总共需要遍历两次字符串。

2019-01-25 09:15:57 124

原创 PAT-A 1089 Insert or Merge (25 point(s)) / PAT-B 1035 插入与归并(25)

思路:就是要写非递归的归并排序算法,对于两种算法,每一轮排序后比较当前状态和给定状态是否匹配,如果匹配就输出,否则继续。

2019-01-24 15:30:10 147

原创 PAT-A 1044 Shopping in Mars (25 分)

思路:使用数组diamond来保存每颗钻石的价值。设置一个数组sum,sum[i]表示从第0颗钻石到第i颗钻石的价值的和,显然sum严格递增。这样从第 i 颗钻石到第 j 颗钻石之间的钻石的价值为sum[ j ] - sum[ i ] + diamon[ i ]。比如,第2颗钻石到第5颗钻石累计的价值为:sum[5] - sum[2] + diamond[2] = 21 - 6 + 1 = 16.这里从0开始计数,只在处理输出的时候将 下标加1即可。diamond: 3     2     1    

2019-01-19 22:25:26 164

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除