自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 判断C语言中的变量命名是否合法

返回会显示为0/1,若是题目明确要求显示TRUE/FALSE,可以讲输出语句稍微修改为。写一个程序,判断C语言中的变量命名是否合法。

2023-03-10 00:00:00 1125

原创 中缀转后缀

编写一程序,将中缀表达式转化为后缀表达式(含括号情况)。使用vector模拟栈(个人习惯) 用stack更方便。文件中读取输入,将结果输出到。假设输入只有字母与符号。

2023-03-10 00:00:00 103

原创 最长回文子串

给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。

2023-03-06 20:51:37 76

原创 最长公共子序列

输出包括两行,第一行代表字符串str1,第二行代表str2。(1≤length(str1),length(str2)≤5000)时间复杂度O(n∗m)O(n*m)O(n∗m),空间复杂度O(n∗m)O(n*m)O(n∗m)。(n,m分别表示两个字符串长度)给定两个字符串str1和str2,输出两个字符串的最长公共子序列。如果最长公共子序列为空,则输出-1。输出一行,代表他们最长公共子序列。如果公共子序列的长度为空,则输出-1。"123456"和“12C4B6”都是最长公共子序列,任意输出一个。

2023-03-06 15:42:12 62

原创 最长递增子序列

给定数组arr,设长度为n,输出arr的最长递增子序列。参考我之前写的两篇关于对于动态规划的分析,这一题主要的思想还是用一个dp数组来记录以arr[i]结尾的最长不下降子序列长度以及其前序元素。输出两行,第一行包括一个正整数n(n

2023-03-03 18:35:03 152

原创 最大连续子序列和

要求当前元素为结尾的最长连续序列和,只有两种情况:第一种为以前一个元素为结尾的最长连续序列和的值大于0,则以当前元素为结尾的最长连续序列和=以前一个元素结尾的最长连续序列和+当前元素。第二种为以前一个元素为结尾的最长连续序列和的值小于等于0,则以当前元素为结尾的最长连续序列和=当前元素。

2023-03-02 15:46:07 708

原创 简单动态规划问题的基本方法

值得注意的是,一个问题必须拥有重叠子问题和最优子结构才能用动态规划解决。重叠子问题是指复杂问题是由重复进行的子问题来解决实现的,也就是重复一定的步骤才能完成目标问题;最优子结构是指所要求得的复杂问题的最优解,是能够由子问题的最优解构造的,也就是分解后的子问题的最优解决方案,是最后复杂问题最优解结构的一部分。

2023-03-02 14:43:13 90

原创 PAT A 2021年春 7-4 Recycling of Shared Bicycles (30 分) AC代码(Floyd算法)

7-4 Recycling of Shared Bicycles (30 分)There are many spots for parking the shared bicycles in Hangzhou. When some of the bicycles are broken, the management center will receive a message for sending a truck to collect them. Now given the map of city, yo

2021-09-11 21:05:12 184

原创 PAT A 2021年春 7-3 Structure of Max-Heap (25 分) AC代码(堆的插入,向上调整)

7-3 Structure of Max-Heap (25 分)In computer science, amax-heapis 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 greater than or equal to the key of C. A common impl..

2021-09-11 21:02:33 110

原创 PAT A 2021年春 7-2 Lab Access Scheduling (25 分) AC代码(区间贪心)

7-2 Lab Access Scheduling (25 分)Nowadays, we have to keep a safe social distance to stop the spread of virus due to the COVID-19 outbreak. Consequently, the access to a national lab is highly restricted. Everyone has to submit a request for lab use in ad

2021-09-11 20:59:13 103

原创 记PAT 甲级 2021年 秋季考试 经验总结、线上考试细节、考场题解

1、简单回顾今天下午考完了秋季的考试,最终得了97分,第一题扣了3分,非常遗憾。还有一个多小时的时候就已经97了,回来和第一题的剩余3分周旋到最后,没能发现问题所在,不停考虑各种,我觉得可能是陷在已有的题目思维里了。不过也算是给自己在考研时间中花费的准备PAT的时间一个交代。这次的题目总体来说常规,三四题经典图加树,不像春季那么不常规,没考过的关键路径还是没考第一题 我没满分,第一题一直没什么类型可言第二题 应该可以算是考察STL的使用,还有一些sort之类的使用第三题 一道图的题,我感

2021-09-11 20:51:21 1689 8

原创 PAT A 2020年春 7-4 Replacement Selection (30 分) AC代码

7-4 Replacement Selection (30 分)When the input is much too large to fit into memory, we have to doexternal sortinginstead of internal sorting. One of the key steps in external sorting is to generate sets of sorted records (also calledruns) with limite...

2021-09-10 23:06:58 192

原创 PAT A 主要数据结构知识点实用模块模板

目录1、二叉树2、并查集3、贪心算法4、最短路径5、拓扑排序6、关键路径还有Hash、DFS、BFS(考察不多,使用队列) 还是更多应结合题目练习使用,考察比较灵活整理总结不易,希望大家顺手给个赞和关注,谢谢大家!!!附上常用的小模块集合常用STL容器总结(待更新)...

2021-09-10 12:09:10 202

原创 PAT A 备考实用小模块集合

1、素数素数判断函数和获取素数表的写法。(二者是独立的,选择使用)bool is_prime(int x){ //素数判断 if(x==0||x=1) return false; int k=(int)sqrt(x*1.0); for(int i=2;i<=K;i++){ if(x%i==0) return false; } return true;} //素数筛(埃氏筛法) int P[MaxN]={0};//0代表为素数,1代表为负数 vector<in

2021-09-09 21:57:26 259

原创 PAT备考之 关键路径 专题

虽然到目前为止,关键路径没有考过,但是近年之前没考过的拓扑排序和Floyd算法都有考,故稍微了解准备一下关键路径。在关键路径之前,有个最长路径的求法,在没有正环的图中,边权全部取相反数,使用Bellman-Ford算法即可。而对于关键路径问题(有向无环图),除了动态规划的解法,比较常规的是使用拓扑排序。具体过程:在拓扑排序的基础之上,进行一次正向拓扑和一次逆向拓扑,用ve[]数组和vl[]数组来更新每个事件最早和最晚的时间。我还是按照自己习惯使用结构体数组和邻接矩阵记录点与点,还有边的情况。

2021-09-09 21:01:31 240

原创 PAT备考之 最短路径 专题

PAT A中30分答题常考题1、Dijkstra算法+DFS(重点)(无负边权)单源最短路径问题万能通法,可以回溯路径,选取多条件最优路径以在最短路径前提下的最小花费问题为例(其余条件根据题目变通)在主函数中直接 Dijkstra(start); DFS(end);即可,path记录的就是有约束下的最短路径int G[maxN][maxN]; //记录两点间距离 int C[maxN][maxN]; //记录两点间花费 int start; //记录起点 int d[ma..

2021-09-09 17:10:56 190

原创 PAT备考之 拓扑排序 专题

拓扑排序可以用于1、有前提条件的事件是否可以进行的判断2、有向无环图的判断下面是我自己比较习惯的写法。(TIP:如果题目条件中有说,当有多个事件可以进行时,优先进行序号小的,那么就可以把queue<int> q 换为priority_queque<int> q,即可直接实现)//顶点数为Nstruct node{ int inD; vector<int> next;}Node[N];//在主函数中存储好结点间关系bool tpsort()

2021-09-09 15:31:14 156

原创 PAT备考之 贪心算法 专题

贪心主要有两种问题,分为简单贪心和区间贪心1、简单贪心 比较好理解和思考;例如已有些单个数字怎样组合最大;出售固定量商品,怎样组合最赚钱。2、区间贪心(1)在一个大的区间内,尽量放入给出的小区间,要求两两不相交,一般求能放入多少个区间,ans即为放入区间数。struct inteval{ int x,y;};bool cmp(const inteval a,const inteval b){ if(a.y!=b.y) return a.y>b.y; ret...

2021-09-09 15:14:14 204

原创 PAT备考之 并查集 专题

对于并查集,记住三个模块即可看到并查集题目,直接二话不说,按顺序三个模块一写,直接用。1、father[N]数组int father[N];数值初始化://写在main函数里for(int i=0;i<n;i++){ father[i]=i;}2、findfather(x)函数(带路径压缩,可以缩短查找时间)int findfather(int x){ if(father[x]==x){ return x; }else{ int F=findfath

2021-09-09 12:35:46 139

原创 PAT备考之 二叉树 专题

二叉树的考题能不建树就不建树,建树也用静态比较简单1、序列转换 作为核心考点树里的核心,需要非常熟练理解掌握树序列的转化(不建树)。做题时有一个思想是,有了包含中序的两个序列,树就有了,其余问题都可在序列上进行。 理解是关键,不要死记硬背。vector<int> pre,in,post,le[N] (记录前序、中序、后序、层序)(1)已知前序中序(pre(N),in(N)),转后序(记录层序)void trail(int r...

2021-09-09 12:15:33 198

原创 PAT A 2020年冬 7-3 File Path AC代码

7-3 File Path (25 分)The figure shows the tree view of directories in Windows File Explorer. When a file is selected, there is a file path shown in the above navigation bar. Now given a tree view of directories, your job is to print the file path for an

2021-09-09 10:35:37 100

原创 PAT A 2020年冬 7-2 Subsequence in Substring AC代码

7-2 Subsequence in Substring (25 分)Asubstringis a continuous part of a string. Asubsequenceis the part of a string that might be continuous or not but the order of the elements is maintained. For example, given the stringatpaaabpabtt,pabtis a subs...

2021-09-09 10:31:06 86

原创 PAT A 2020年冬 7-1 The Closest Fibonacci Number AC代码

7-1 The Closest Fibonacci Number (20 分)TheFibonacci sequenceFn​is defined byFn+2​=Fn+1​+Fn​forn≥0, withF0​=0andF1​=1. Theclosest Fibonacci numberis defined as the Fibonacci number with the smallest absolute difference with the given integerN....

2021-09-09 10:29:22 89

原创 PAT 2020年秋 7-4 Professional Ability Test (30 分) AC代码(拓扑排序以及DFS)

7-4 Professional Ability Test (30 分)Professional Ability Test (PAT) consists of several series of subject tests. Each test is divided into several levels. Level A is aprerequisite (前置要求)of Level B if one must pass Level A with a score no less thanSin...

2021-09-06 22:10:15 531

原创 PAT 2020年秋 7-3 Left-View of Binary Tree (25 分) AC代码

7-3 Left-View of Binary Tree (25 分)Theleft-viewof a binary tree is a list of nodes obtained by looking at the tree from left hand side and from top down. For example, given a tree shown by the figure, its left-view is { 1, 2, 3, 4, 5 }Given the ino..

2021-09-06 22:05:08 183 1

原创 PAT 2020年秋 7-2 How Many Ways to Buy a Piece of Land (25 分) AC代码

7-2 How Many Ways to Buy a Piece of Land (25 分)The land is for sale in CyberCity, and is divided into several pieces. Here it is assumed that each piece of land has exactly two neighboring pieces, except the first and the last that have only one. One can

2021-09-06 22:02:45 127

原创 PAT 2020年秋 7-1 Panda and PP Milk (20 分) AC代码

7-1 Panda and PP Milk (20 分)PP milk (盆盆奶)is Pandas' favorite. They would line up to enjoy it as show in the picture. On the other hand, they could drink in peace only if they believe that the amount of PP milk is fairly distributed, that is, fatter pan

2021-09-06 21:59:16 255 3

原创 PAT 2020年春 7-3 Safari Park AC代码

7-3 Safari Park (25 分)A safari park(野生动物园)hasKspecies of animals, and is divided intoNregions. The managers hope to spread the animals to all the regions, but not the same animals in the two neighboring regions. Of course, they also realize that this...

2021-09-06 21:43:15 178

原创 PAT 2020年春 7-2 The Judger AC代码(使用unordered_set)

7-2 The Judger (25 分)A game of numbers has the following rules: at the beginning, two distinct positive integers are given by the judge. Then each player in turn must give a number to the judge. The number must be the difference of two numbers that are p

2021-09-06 21:39:39 96

原创 PAT 2020年春 7-1 Prime Day AC代码

7-1 Prime Day (20 分)The above picture is from Sina Weibo, showing May 23rd, 2019 as a very cool "Prime Day". That is, not only that the corresponding number of the date20190523is a prime, but all its sub-strings ended at the last digit3are prime numb...

2021-09-06 21:35:02 118

原创 PAT 2019年冬 7-4 Cartesian Tree AC代码

根据题目描述,tree函数根据给出的中序和性质遍历树,然后每层记录在le[]中#include<iostream>#include<vector>using namespace std;vector<int> in,le[30];int N;void tree(int root,int start,int end,int level){ if(start>end) return; le[level].push_back(in[root]);..

2021-09-06 15:21:49 85

原创 PAT 2019年冬 7-3 Summit AC代码

对于每个人,我用了一个set记录他的好友#include<iostream>#include<vector>#include<set>using namespace std;static set<int> s[210];static set<int> f;int N,M,K;int main(){ cin>>N>>M; for(int i=0;i<M;i++){ int a,b; s..

2021-09-06 15:14:45 113

原创 PAT 2019年冬 7-2 Block Reversing AC代码

用algorithm中的reverse函数比较方便#include<iostream>#include<vector>#include<algorithm>using namespace std;int start,N,K;vector<int> L,ans;int cnt=0;struct node{ int data,next;}Node[100000];void trail(int index){ if(index==-1

2021-09-06 15:08:02 82

原创 PAT A 2019年秋季 7-4 Dijkstra Sequence AC代码

一道dijkstra算法的模板题对于所谓的Dijkstra Sequence,直接判断给出结点序列到起点距离(d[x])是否是不严格增序即可#include<iostream>#include<vector>using namespace std;int Nv,Ne,K;int inf=1000000000;int G[1001][1001];int d[1001];void dijkstra(int s){ fill(d,d+1001,inf);

2021-09-01 22:10:30 135

原创 PAT A 2019年秋季 7-3 Postfix Expression AC代码

对于如题给出的语法树,每个结点只有三种情况:1、左子不空,右子不空2、左子空,右子不空3、左子空,右子空根据题意,对应的输出应为1、( 左子树内容 右子树内容 当前结点内容 )2、(当前结点内容 右子树内容 )3、(当前结点内容)按照这个去递归语法树即可tips:我一开始根据表达式可能的情况,对加乘除以及减四个符号分开专门判断,最后一个测试点没法通过。说不定最后一个测试点的符号不一定是题中给出的符号样式或者输出是一个不合法的后缀表达式。(个人猜测) 所以抓住语法树的结构来

2021-09-01 22:07:12 164

原创 PAT A 2019年秋 7-2 Merging Linked Lists AC代码

我就按照题目意思,先用结构体记录链表,然后遍历短的(go1函数)(先从b1跑一遍,如果记录下的数量>N/2,说明b1开始的是长的,那么就重新跑a1),记录下短的地址顺序,再去跑长的,边跑边记录并插入短的(go函数)最后按照格式输出#include<iostream>#include<vector>#include<algorithm>using namespace std;int a1,b1,N;struct node{ int num,n

2021-09-01 21:55:38 187

原创 PAT A 2019年秋 7-1 Forever AC代码

这道题很搞心态,用了素数判断、最大公约数以及各数位求和(分别写为了3个函数)但是对范围内的数字进行暴力遍历的话,最后两个测试点会超时需要根据测试结果想到所有满足条件的数都是以99结尾,这样只遍历99结尾的数才不会超时(其实不大好想到,要多试一些数据,还有题目的名字联想)#include<iostream>#include<cmath>#include<vector>#include<algorithm>using names.

2021-09-01 21:50:12 94

原创 PAT A 2019春 7-4 Structure of a Binary Tree AC代码

一开始看到题目的时候有点懵,这个输入有点让人头大按照种类不断细分来写,对于每个输入一个一个词读取判断还有就是根据后序和中序建树,为方便判断结构体多存一点信息我根据后序的顺序对每个数字编号,用了一个map记录对应关系#include<iostream>#include<vector>#include<unordered_map>using namespace std;int N,M;vector<int> post,in;.

2021-09-01 17:12:04 69

原创 PAT A 2019春 7-3 Telefraud Detection AC代码

题目稍微有点复杂最好用并查集,形成gang第一次写输出的时候看错题目了,题目只要求按照gang的首个数字大小输出,不要求按照gang的人数排序,读题目要再小心一点#include<iostream>#include<vector>using namespace std;int K,N,M;int t[1001][1001]={0};int father[1001];int findfather(int x){ if(father[x]==x){.

2021-09-01 17:07:19 147

原创 PAT A 2019年春 7-2 Anniversary AC代码

用了一个set记录校友,读取来宾的时候做两件事:1、判断是否是校友,是则ans1++2、判断是否是最年长的,是则更新ans2和生日最小值#include<iostream>#include<set>#include<algorithm>using namespace std;int N,M;int ans1=0,Min=100000000;string ans2;set<string> alumni;int main().

2021-09-01 15:13:08 89

空空如也

空空如也

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

TA关注的人

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