PAT
PAT题解
Herman · H
这个作者很懒,什么都没留下…
展开
-
PAT乙级:1015 德才论 (25分)
1015 德才论 (25分)宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”现给出一批考生的德才分数,请根据司马光的理论给出录取排名。输入格式:输入第一行给出 3 个正整数,分别为:N(≤105),即考生总数;L(≥60),为录取最低分数线,即德分和才分均不低于 L 的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定原创 2020-11-13 17:59:41 · 188 阅读 · 0 评论 -
1067 Sort with Swap(0, i) (25 point(s)) 超时情况
原题链接一开始兴高采烈写完,以为很简单就ac了,结果蹦出两个超时。由于我基本用的scanf,所以输入数据应该不会导致超时,一定是中间某个步骤复杂度太大导致超时了。所以我把目光放在的两个循环上。很显然,我中间用到了两个嵌套循环,复杂度是二次方级,我需要优化一下降低复杂度。我想了很久没有想到解决的办法,觉得不历遍数组是不行的(最搞笑的是我尝试甚至还用了随机数,结果全部超时)。后来我翻看了下算法笔...原创 2019-07-23 22:36:51 · 233 阅读 · 1 评论 -
1037 Magic Coupon (25 point(s)) 踩坑心得
1037 Magic Coupon (25 point(s))原题链接一开始代码写成这个样子#include<stdio.h>#include<iostream>#include<algorithm>bool cmp(int a, int b) { return a > b;}using namespace std;int main()...原创 2019-07-23 16:47:09 · 299 阅读 · 0 评论 -
1047 编程团体赛 (20 point(s)) 关于scanf函数的输入方法
在题目中,要求输入的格式为63-10 9911-5 87102-1 0102-3 10011-9 893-2 61一开始我用的cin,自然要想办法去掉 ‘-’ ,于是就煞费苦心写了个函数去了 ‘-’ 。后来发现,根本不需要去 ‘-’ ,scanf函数就能帮你去。#include <stdio.h>#include <cstring>#includ...原创 2019-07-15 18:54:45 · 125 阅读 · 0 评论 -
1039 到底买不买 (20 point(s)) 关于用fgets会出现情况2 4报错的问题
1039 到底买不买 (20 point(s)) 关于用fgets会出现情况2 4报错的问题一开始,我使用的是fgets录入字符串就像下面那样#include <iostream>#include <stdio.h>#include <cstring>using namespace std;int main() { int Hash_re...原创 2019-07-13 10:40:40 · 97 阅读 · 0 评论 -
1096 Consecutive Factors (20分)
逻辑题:1096 Consecutive Factors (20分)PAT甲级: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 ...原创 2020-01-25 12:19:48 · 134 阅读 · 0 评论 -
1078 Hashing (25 point(s)) 笔记
原题连接Quadratic probing 平方探查法中文名为平方探查法。用于解决hash的collision。有算法笔记书的打开讲hash那一节的,曾经提到过。(忘了的活该卡一下午呜呜呜)现在想想还是好气,以为那个词不重要(主要是看不懂)愣是卡了2小时……它的计算公式为...原创 2019-09-22 19:47:56 · 152 阅读 · 1 评论 -
A1088 Rational Arithmetic (20 point(s))/B1034 有理数四则运算 (20 point(s)) 笔记
#include<stdio.h>#include<iostream>using namespace std;long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a%b);}class Fraction {public: long long...原创 2019-09-22 14:37:41 · 117 阅读 · 1 评论 -
1081 Rational Sum (20 point(s)) 笔记
A级81题笔记原题链接比较简单的一道题,分数的加减法运算。下面给出我自己的accept代码。#include<stdio.h>#include<iostream>#include<string>#include<algorithm>using namespace std;int gcd(long int a, long int b) ...原创 2019-09-21 09:43:23 · 100 阅读 · 0 评论 -
图的邻接表+DFS写法 (PAT甲级 **1021** **Deepest Root** **(25**分))
图的邻接表+DFS写法例题:1021 Deepest Root (25分)1021 Deepest 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 suppose...原创 2019-12-27 20:34:41 · 98 阅读 · 0 评论 -
根据完全二叉树计算根节点位置 **1064** **Complete Binary Search Tree** (30分)
根据完全二叉树计算根节点位置例题: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 onl...原创 2019-12-21 09:52:49 · 360 阅读 · 0 评论 -
前中后序建立树或者直接历遍
前中后序建立树或者直接历遍代码实现void postOrder(int root,int start,int end){ if (start > end) return; int index = start; while (inOrder[index] != preOrder[root] ) index++; postOrder(root + 1, start, ind...原创 2019-12-18 09:59:46 · 102 阅读 · 0 评论 -
用DFS实现层序历遍 c++实现
原创 2019-12-10 15:58:39 · 119 阅读 · 0 评论 -
avl平衡树的基本操作C++函数实现
原创 2019-12-08 14:44:44 · 84 阅读 · 0 评论 -
KMP算法是如何确定无效偏移的
我们先看一个例子:下面是一个待匹配的字符串,我们对里面有什么一无所知,就像这样然后我们有一个待匹配的模式串,这个我们是知道它里面有啥的好的,我们开始匹配,在红箭头处我们发现匹配失败我们可以得出一个什么隐含条件?我们可以得知的是,被匹配字符串的一段是和模式串相同的。好像是废话?那我问你,凭借这个,你能猜得到下一个偏移是不是有效的吗?或者说在哪次偏移才是有效的?记住,你现在...原创 2019-10-22 17:18:48 · 228 阅读 · 0 评论 -
1010 Radix (25 point(s)) 刷题踩坑记录
原题链接下面给出我自己的ac代码#include<cstdio>#include<string>#include<iostream>#include<cmath>#include<algorithm>using namespace std;char Map[256];void hashMap() { for (char...原创 2019-08-14 18:29:43 · 608 阅读 · 0 评论 -
1030 完美数列 (25 point(s))
原题连接,点击进入下面是我没有敲出ac的代码,直到写完博客前我也没有发现我的代码的纰漏在哪里。会有两个情况会出现wrong answer。#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;int search(long long group[],int ...原创 2019-08-10 14:58:40 · 112 阅读 · 0 评论 -
最大最小堆的判定
最大最小堆的判定堆类型的判定 就是判定堆是最大堆,最小堆还是不是堆。看到很多算法都是自上而下的,看起来不是特别简洁,有一点乱。 在这里记录一下我自己写的自下而上的堆判定函数。const int notHeap = 0, maxHeap = 1, minHeap = -1;int cmp(int parent,int child){ if (parent > child)...原创 2020-01-25 12:36:16 · 1277 阅读 · 1 评论 -
PAT题目的单链表题目
PAT题目的单链表题目 PAT的单链表基本都是静态链表。可以当成常规的单链表来做,会比较符合出题人的意图。但也有一些别的办法来完成静态链表的题目。1097 Deduplication on a Linked List (25分)Given a singly linked list L with integer keys, you are supposed to remove the no...原创 2020-01-25 22:24:01 · 191 阅读 · 0 评论 -
A 1032 Sharing (25 point(s)) 笔记
A 1032 Sharing (25 point(s))用静态链表实现的题目,比较简单。原题链接下面给出自己的accept代码。#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;const int Maxsize = 100010;class no...原创 2019-09-24 15:05:43 · 92 阅读 · 0 评论 -
完全二叉树判定方法
完全二叉树判定方法 把完全二叉树以数组的形式存储起来,只要结点是连续存放,就可以说明这棵树是完全二叉树。 也就是说,只要最后一个结点的坐标与结点的总数相同,说明这棵树是完全二叉树。 下面给出一道例题:甲级PAT:1110 Complete Binary Tree (25分)1110 Complete Binary Tree (25分)Given a tree, you ar...原创 2020-01-26 15:21:21 · 474 阅读 · 0 评论