当前位置:网站首页>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
边栏推荐
- JVS开发套件产品定位
- IDEA 配置方法注释自动参数
- [Virtualization Ecological Platform] Platform Architecture Diagram & Ideas and Implementation Details
- Full GC (Ergonomics)排查分析
- The latest MySql installation teaching, very detailed
- In Excel using ODBC consumer SAP ABAP CDS view
- VBA实现双击单元格自动输出对号再次双击取消对号
- Life is endless, there are more questions, simple questions to learn knowledge points
- 文件包含漏洞
- Docker搭建Mysql主从复制
猜你喜欢
机器学习基本概念
AWS Amazon cloud account registration, free application for 12 months Amazon cloud server detailed tutorial
502 bad gateway原因、解决方法
DCM 中间件家族迎来新成员
最新MySql安装教学,非常详细
线性表的基本概念
数据持久化技术——MP
Android studio connects to MySQL and completes simple login and registration functions
Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
基于C51实现按键控制
随机推荐
MySQL limit paging query and performance issues
The item 'node.exe' was not recognized as the name of a cmdlet, function, script file, or runnable program.
IDEA 配置方法注释自动参数
mysql automatically adds creation time and update time
关于Mysql数据库的介绍
St. Regis Takeaway Project: New dishes and dishes paged query
AWS Amazon cloud account registration, free application for 12 months Amazon cloud server detailed tutorial
Use jOOQ to write vendor-agnostic SQL with JPA's native query or @Formula.
DCM 中间件家族迎来新成员
Chrome开发自定义右键菜单实现快速跳转到指定页面
Spark GC日志分析
CameraToolUnity中两种摄像机的两种观察控制方式
「R」使用ggpolar绘制生存关联网络图
三相PWM整流器预测直接功率控制
ESP8266-Arduino编程实例-HDC1008温度湿度传感器驱动
Caused by: 类找不到: org.apache.flink.table.planner.delegation.ParserFactory或者ExecutorFactory
JVM 运行时数据区与JMM 内存模型详解
瑞吉外卖项目:文件的上传与下载
荣耀手机参数写错,客服认为没错
Android studio连接MySQL并完成简单的登录注册功能