
pta
smiling~
努力会被看得到的
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PAT 甲级 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-11-29 10:55:40 · 150 阅读 · 0 评论 -
PAT 甲级 1064 Complete Binary Search Tree (30 分)
题意:给出n个数的值,让你用这n个数建一颗完全二叉搜索树,然后进行层序遍历。方法1:分治思想先把值排序,从根节点开始安排,每层结点数为1,2,4, 8 … 看安排到哪一层安排不够了,就尽量从左往右安排结点,记录左子树一共放了多少个,假如放了x个,那么当前的根节点的值不就是a[x+1]么,然后对于左区间和右区间也以此类推,进行分治。之所以用数组存储,是因为求得的是完全二叉树,一个结点的左孩子...原创 2019-11-26 19:52:02 · 201 阅读 · 0 评论 -
PAT 甲级 1060 Are They Equal (25 分) (模拟)
If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×105 with simple chopping. Now given the number of sig...原创 2019-11-24 21:41:35 · 204 阅读 · 0 评论 -
PAT 甲级 1056 Mice and Rice (25 分) (模拟)
Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice...原创 2019-11-22 17:14:55 · 182 阅读 · 0 评论 -
PAT甲级 1052 Linked List Sorting (25 分)
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...原创 2019-11-22 14:32:49 · 90 阅读 · 0 评论 -
PAT 甲级 1032 Sharing (25 分) (邻接表)
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 ...原创 2019-11-21 22:57:53 · 260 阅读 · 0 评论 -
PAT 甲级 1034 Head of a Gang (30 分) (并查集)
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 between A and B, we say that A and B is related. The weight of a ...原创 2019-11-17 16:04:10 · 232 阅读 · 0 评论 -
PAT 甲级 1047 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 Sp...原创 2019-11-17 12:34:07 · 150 阅读 · 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 ...原创 2019-11-17 11:29:02 · 201 阅读 · 0 评论 -
PTA 甲级 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 subt...原创 2019-11-16 20:03:32 · 254 阅读 · 0 评论 -
PAT 甲级 1024 Palindromic Number (25 分) (大数加法)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers...原创 2019-11-09 15:47:13 · 143 阅读 · 0 评论 -
PAT 甲级 1021 Deepest Root (25 分)
题意:找到能让树的深度最深的结点,若不唯一,升序输出。如果给出的图不连通,输出联通块的个数。思路:并查集+求树的直径。求出树最深是多少,然后每个结点dfs一次,如果等于那个最深的深度, 如果等于那个最深的深度就输出。代码:include<iostream>#include<cstring>#include<cstdio>#include<al...原创 2019-11-08 19:15:31 · 218 阅读 · 0 评论 -
PAT 甲级 1020 Tree Traversals (25 分)
题意:已知后序和中序遍历,求层序遍历。思路:正常建二叉树,然后广搜即可。代码:#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<vector>#include<queue>#include<map...原创 2019-11-08 18:41:15 · 151 阅读 · 0 评论 -
PAT 甲级 1015 Reversible Primes (20 分)
题意:给一个十进制数n,以及基数d。求出n在d进制下的数的翻转对应的数x。如果n和x都是质数输出Yes,否则输出No。刚开始没太理解题意,,以为给的是d进制的数,,,,思路:模拟就行了,注意1和0不是质数。代码:#include<iostream>#include<cstring>#include<cstdio>#include<alg...原创 2019-11-08 15:45:42 · 134 阅读 · 0 评论 -
PAT甲级 1014 Waiting in Line (30 分)
题意:n个窗口,每个窗口可以排m人。有k为顾客需要办理业务,给出了每个客户的办理业务时间。银行在8点开始服务,如果窗口都排满了,客户就得在黄线外等候。如果有一个窗口用户服务结束,黄线外的客户就进来一个。如果有多个可选,选窗口id最小的。输出查询客户的服务结束时间。如果客户在17点或者以后还没开始服务,就输出Sorry如果已经开始了,无论多长都会继续服务的。思路:建立一个优先队列,存储...原创 2019-11-08 15:08:26 · 225 阅读 · 0 评论 -
PAT 甲级 1010 Radix (25 分) (二分+模拟 )
题意:给两个不超过10位的数和其中一个数的进制,求使得两个数相等的最小的另一个数的进制,若不存在,输出Impossible。思路:题目说输入的数最大为35,我理所当然认为最大进制就是36,进行了枚举。结果过不了,,好吧,事实上输出的进制多大都有可能,只要使得两数相等,那么枚举肯定不行了,需使用二分,那么上限为多少呢,尽可能大就好了,我做的时候直接将上限设为了1e18,因为进制数必须比给出的数字中...原创 2019-10-26 13:15:44 · 183 阅读 · 0 评论 -
PTA L2-028 秀恩爱分得快
古人云:秀恩爱,分得快。互联网上每天都有大量人发布大量照片,我们通过分析这些照片,可以分析人与人之间的亲密度。如果一张照片上出现了 K 个人,这些人两两间的亲密度就被定义为 1/K。任意两个人如果同时出现在若干张照片里,他们之间的亲密度就是所有这些同框照片对应的亲密度之和。下面给定一批照片,请你分析一对给定的情侣,看看他们分别有没有亲密度更高的异性朋友?输入格式:输入在第一行给出 2 个正整...原创 2019-05-07 20:47:01 · 1164 阅读 · 0 评论