当前位置:网站首页>PAT exam summary (exam experience)
PAT exam summary (exam experience)
2022-07-31 12:06:00 【Full stack programmer webmaster】
大家好,又见面了,我是你们的朋友全栈君.
pat试题总结
A summary of the traversal problem
- dfs中,If it is a graph with cycles,要设置visitedArrays prevent looping,同时在dfsbefore the function exitsvisitedThe array is set accordinglyfalse,Otherwise, other paths cannot traverse the node;
- 在问题中,如果要求“Select several elements from a sequence to satisfy the condition”,可以考虑dfs,如1103 Integer Factorization (30分)和7-1 Forever (20分);
- 在写dfs前,List all variables that need to be set,然后在dfs边界上,Modifications to the values of these variables are considered one by one,You can avoid missing changes to a variable;
- Think carefully before you start writing code“What is determined by what”可以省去debugtime mindset,如1131 Subway Map (30分)A line can be determined by using two neighbors as keys,But investigate“Which line both neighbors belong to”Can't figure out the line;又如1018 Public Bike Management (30分),Number of departuressendand recovery numbersbackdoes not satisfy the optimal substructure,Choosing a path by a greedy algorithm will not work.
字符串处理总结
- 字符串处理中,注意利用sscanf,The numbers in the string can be read in the format,如
sscanf(s, “The root is %d”, &root)提取int型变量root; - When there are many illegal situations,Not to judge illegal situations one by one,Instead, only legal cases are allowed to pass,Such as judging whether it is a legal number:Only one decimal point is possible、several digits、There can only be one negative sign and it appears in the header.
- Familiar with the conversion of numbers and strings.
Summary of math problems
- in math problems,常用的函数如下:
//辗转相除法求最大公因数
int gcd(int a, int b) {
return b == 0 ? a: gcd(b, a % b);
}//A sieve lists the prime numbers
bool prime[100];
void getPime() {
fill(prime + 2, prime + 100, true);
for(int i = 2; i < 100; i++) {
if(prime[i]) {
int factor = 2;
while(i * factor < 100) {
prime[i * factor] = false;
}
++factor;
}
}
}//判断素数的函数
bool isPrime(int num) {
int n = sqrt(num);
for(int i = 0; i <= n; i++) {
if(num % i == 0)
return false;
}
return true;
}- in some processing,Negative signs can be considered、The decimal point is handled separately,It can effectively simplify the judgment conditions;
- 进制转换,Mainly use the remainder method of division and base multiplication.
- When there is no good way,Try to find regular simplification solutions.
A summary of the sorting problem
- Memorize the writing of various sorting codes. 插入排序:Inserts the head element from the unordered subarray into the ordered subarray each time; 冒泡排序:The cursor scans from front to back,If the two elements before and after are in reverse order,则交换; 选择排序:Choose the smallest one from the unordered part at a time,Swap with the elements after the ordered part; 快速排序:Selects an element in the array as pivot,Hide it to the far left,两个游标left, right根据pivotThe size keeps swapping elements,When two cursors meet,leftIt is indicatedpivot应该放的位置; 堆排序:先自底向上建堆,Each time an element is taken from the top of the heap,Top with the element at the end of the array,Then filter down the top element of the heap;
- 对时间的处理,You can first convert the time into seconds,Convert back to hours, minutes and seconds if necessary.
- Eliminate invalid data if necessary,Find results from valid data;
- When a question has multiple queries,Process the data first,Results can be returned directly when processing a query.If every query is sorted once,可能会超时;
- Read the sorting criteria carefully,Avoid omissions or mistakes.
Summary of tree problems
- Memorize the code for constructing the tree given two sequences as well1119 Pre- and Post-order Traversals (30分)Preorder and postorder are not uniquely constructed;
- 熟记AVL树左旋、Right-handed spelling,Note that the height of the child node and the parent node needs to be updated after the rotation,Pay attention to the timing of updating the altitude;
- Write the template code first,Then modify as needed;
- Consider the logical inconsistency between the implemented code and the description of the problem,如1135 Is It A Red-Black Tree (30分)要求的是”The number of black nodes from each node to the leaf node is the same“,Not just root node to leaf node.
A summary of the simulation problem
- Choose the data structure appropriately,如1129 Recommendation System The number of occurrences of data is constantly changing,At the same time, it is required to be ordered according to the number of occurrences,So consider the red-black tree implementation
set; - 充分考虑、Simplify the conditions to be met by the simulated event,如1128 N Queens Puzzle (20分)中,”Two queens cannot be on the same diagonal“,It shows that the slope of the line connecting the two queens cannot be 1;
- When the simulated event has a timeline,Consider setting a variable to simulate the passage of time.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/128736.html原文链接:https://javaforall.cn
边栏推荐
猜你喜欢

机器学习基本概念

deeplab implements its own remote sensing geological segmentation dataset

5 个开源的 Rust Web 开发框架,你选择哪个?

After class, watching the documentation and walking back to the lab, I picked up the forgotten SQL operators again

Power BI----几个常用的分析方法和相适应的视觉对象

JVS设置不同应用的登录时效时间

JVS开发套件产品定位

R语言做面板panelvar例子

mysql根据多字段分组——group by带两个或多个参数

The item 'node.exe' was not recognized as the name of a cmdlet, function, script file, or runnable program.
随机推荐
Candence学习篇(11) allegro中设置规则,布局,走线,铺铜
快速学完数据库管理
Full GC (Ergonomics)排查分析
The latest MySql installation teaching, very detailed
CameraToolUnity中两种摄像机的两种观察控制方式
机器学习基本概念
一文带你了解redux的工作流程——actionreducerstore
lotus-local-net 2k v1.17.0-rc4
JVM 运行时数据区与JMM 内存模型详解
MySQL row-level locks (row locks, adjacent key locks, gap locks)
ESP8266-Arduino编程实例-PIR(被动红外)传感器驱动
最新MySql安装教学,非常详细
5 个开源的 Rust Web 开发框架,你选择哪个?
线性表的基本概念
Mysql环境变量的配置(详细图解)
文件包含漏洞
Obsidian设置图床
[Virtualization ecological platform] Raspberry Pi installation virtualization platform operation process
Qt鼠标穿透
Data Lake (19): SQL API reads Kafka data and writes it to Iceberg table in real time