自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 1151 LCA in a Binary Tree (30分) 树、LCA、前序中序确定树。两种思路。

题目链接1151 LCA in a Binary Tree (30分)The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.Given any two nodes in a binary tree, you are supposed to find their LCA.Input Specification:Ea

2020-10-10 19:36:53 146

原创 【PAT】A1115 Counting Nodes in a BST (30分)

解析:这道30分的题10分钟以内可以完成,送命题。最多1000的点故用int level[1010]记录从0~1000层节点数,初始为0。用Max记录当前最大层数。只需要一个插入函数, 在构建搜索树的同时把最大层数记录,并维护level数组即可。树建好了答案也就有了。#include<cstdio>struct node{ node* lchild, *rchild; int data, lv;};int level[1010] = {0}, Max = -1;node* in

2020-08-27 11:28:36 74

原创 【PAT】A1044 Shopping in Mars (25分)

做题链接思路:对这个序列设置两个标志位,left与right 用twopoint的思想,使整体复杂度为O(n).AC代码#include <cstdio>#include <vector>using namespace std;const int maxn = 100010;const int INF = 100000010;int n,m, a[maxn], sum = 0, min_sum = INF;int left = 1 , right = 1;//

2020-06-20 23:09:04 113

原创 【PAT】A1010 Radix (25分)--二分、进制转换

做题链接思路把已知进制的字符串转换为十进制数N1。对另一个字符串str用二分法进行十进制数转换,初始二分区间为(m,h);其中m为最低进制:通过遍历str找到最大字符, 则进制为对应字符转换为数字+1;h为m与N1中较大者。注意点此题数的范围较大,采用long long类型转换为10进制数时可能溢出, 当溢出时, 返回-1;在二分过程中, 若某进制发生溢出, 则表明该进制下str转换成十进制数肯定大于N1, 故应减小进制,对应二分区间右边界更新为 right = mid -1;AC代码//

2020-06-20 21:32:30 193

原创 【PAT】A1038 Recover the Smallest Number (30分)

题目链接思路:用string容器存储字符串,开一个string str[maxn]的空间把输入的字串储存。写一个cmp函数,用sort函数对这些string排序。排好后连接成一个目标字符串string ans,并去掉ans的前导0。输出:去掉前导0都的ans若为空,则输出0, 不为空则输出ans。AC代码#include <cstdio>#include <algorithm>#include <vector>#include <string

2020-06-20 17:41:46 92

原创 【PAT】A1067 Sort with Swap(0, i) (25分)

题目链接思路与总结:这一排序方法的核心思想就是每次让一个数回到正确位置:如样例初始状态{4, 0, 2, 1, 3} 此时数字0在①号位,而①号位本应该是数字1,那么找到数字1,发现它在③号位,故而两数交换位置 得到新数列 即Swap(0, 1) => {4, 1, 2, 0,3};此时数字1在①号位,数字1已归位。这一操作:交换次数cnt+1,并归位一个数。接着重复这一过程。直至所有数字都归位。但还有一个问题忽略了,那就是当数字0在0号位,如数列{0,1,2,4,3},那岂不是没

2020-06-18 19:41:34 90

原创 【PAT】A1033 To Fill or Not to Fill (25分)

–题目链接–总结:按距离对从小到大对加油站站点排序,另多设一个终点站,其距离为最大距离D,油价为0.0。核心思路:从当前站点now寻找行程范围内下一站点next:(1)如果行程范围内无站点可达,则加满油跑一个最大行程,结束。(2)对于行程范围内(加满油可跑的最远距离)可达的站点,从近及远考察:记录最小油价①:若一旦出现油价小于当前now站的油价,则该点即为下一站next。并且油箱加到刚好够到这一站。②若行程范围内的站点油价都高于now站的油价,则其中油价最小的即为next站(在遍历

2020-06-18 10:57:47 112

翻译 如何用递归实现全排列

学习笔记:用递归实现全排列。《算法笔记》的递归章节里有个例子,我觉得很好,全排列用递归实现,首先分析问题:全排列: 输出 1~n这n个整数能形成的所有排列。如1、2、3 的全排列为(1、2、3),(1、3、2),(2、1、3),(2、3、1),(3、1、2),(3、2、1) 这6种递归一定要一个思想是把一个问题分解为同样但不同参数的若干子问题:抄书太麻烦了 ,直接上代码,P115《算法笔记》#include <cstdio>const int maxn = 11;//p为当前排

2020-06-12 20:14:05 2467

原创 【PAT】A1050 String Subtraction (20分)--字符(串)hash

1050 String Subtraction (20分)-----题目地址-----Given two strings S1 and S2, S=S1−S​2 is defined to be the remaining string after taking all the characters in S​2 from S​1. Your task is simply to calculate S1 −S2 for any given strings. However, it might not

2020-06-09 18:25:13 93

原创 【PAT】1092 To Buy or Not to Buy (20分)---简单字符(串)hash

1092 To Buy or Not to Buy (20分)Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in whole p

2020-06-09 17:28:53 69

原创 【PAT】A1084 Broken Keyboard (20分)--简单字符(串)hash

1084 Broken Keyboard (20分)-------题目链接-------On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you are supposed to type, and

2020-06-09 17:03:18 81

原创 【PAT】A1075 PAT Judge (25分)---排序

做题笔记:这道题题目条件逻辑关系还是比较多的:首先结构体定义好struct node{ int id; int score[6]; int sum; //总分 int num; //满分数 bool flag; //是否有过有效提交 node(){ memset(score, -1, sizeof(score));//初始分数为-1 sum = 0; num = 0; flag = false; } }stu[maxn];再是几点注意点,题目逻辑:

2020-06-05 01:43:52 77

原创 【PAT】 A1055 The Worlds Richest (25分)

题目链接1055 The World’s Richest (25分)Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world’s wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain range

2020-06-04 23:37:48 103

原创 【PAT】 A1082 Read Number in Chinese (25分)--字符串处理

题目链接题目详情1082 Read Number in Chinese (25分)Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai si Shi wu Wa

2020-06-04 20:03:00 138

原创 【PAT】1077 Kuchiguse (20分)---字符串处理

1077 Kuchiguse (20分)The Japanese language is notorious for its sentence ending particles.Personal preference of such particles can be considered as areflection of the speaker’s personality. Such a preference is called“Kuchiguse” and is often exaggerat

2020-06-03 21:46:07 227

空空如也

空空如也

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

TA关注的人

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