Take notes on solving the problem of "Sword refers to offer" and "Sword refers to offer"
Notes on solving the problem of sword pointing to offer
I have a total of 50 questions about "Sword finger offer". I have spent time using C ++ over the past two weeks, I would like to make some clever methods, difficulties in writing code, and details that are prone to mistakes here for a simple annotation, but it will not be too detailed. Please refer to the specific algorithm for reference.
The code is too urgent and there are still many imperfections. If you have any errors, please correct them. The address is github: sword_of_offer. Availablegit clone https://github.com/heLomaN/sword_of_offer.git
Command to obtain the code.
Among them, a few questions that cannot be verified are not written code, and some binary tree questions are written code, but it is too troublesome to generate a binary tree.
Solution notes Q3
How do I write statements that declare and initialize two-dimensional arrays?
How does cin determine the end of input?
Q4
The end position of the character array is calculated by 1, and \ 0 is missing. Be careful
Q5
Recursive methods are more concise
Q6
Stl find Algorithm
The performance of vector data passing is poor and should be referenced
The length of the left and right subtree is used to intercept a section. It is wrong to find again.
Q7
The stack pop return value is void, and the top method returns the top value.
Q8
This is rather difficult. Especially non-recursive writing
Think carefully about Boundary Value Processing
Special cases such as 1 0 1 cannot be ignored
Q9
Long type should be used
Q10
Evaluate the binary value of a number to indicate the number of classes 1. Remember: minus 1 and then & itself will always eliminate 1.
Q11
Divide by 2 with>, and use mode 2 with higher efficiency
Error Detection should be added
Q12
If you encounter a number-related question, first consider whether it is a big number problem.
Q13
Copy the value of the next node to the current node, and then delete the next node.
Q14
9du oj requires that the order of the odd or even numbers remain unchanged. The current Code does not meet this requirement.
Q15
node *p,q
Just declare p as a pointer. Be careful.
Reference https://github.com/julycoding/The-Art-Of-Programming-By-July,*
It should be close to the type name
Q16
Drawing to help understand
Q18
! P can be used to judge whether the pointer is null.
Code not tested
Q22
The method is hard to remember. We need to analyze the Rule carefully.
Q25
Code not tested
Q26
The method is hard to remember. Step 3 is not simple enough to separate the linked list.
Q27
Using an auxiliary vector, the method in the book cannot be carefully written.
Q28
This solution cannot process repeated characters, which may lead to repeated
The global array is modified recursively, but the global array needs to be modified after recursion is called. This is the same as the method before and after recursion to call the stack.
8. The Queen's problem can also be solved using this method.
Q29
Finding any number in the array that is K has a mature O (n) algorithm.
Q30
Throw new excetion ("error") in C ++ is incorrect, and the excetion cannot be initialized with a string.
Set and multiset are implemented based on the red and black trees.
Q31
The principle of the first solution is the same as that of the DP Solution.
Q32
The number of times 1 appears between 1 and n 9 is n * 10 ^ (n-1)
Code not tested
Q33
Itoa is not a standard library function, but a library function in linux. It can be replaced by printf.
String can be directly +,>, <operation
Q34
The key is how to ensure that the existing ugly number array is ordered.
Q35
The memset function is in the cstring header file.
Q35
The key is the detailed processing of merge arrays.
Merging and sorting is equivalent to the space of O (n), and the time complexity is increased to O (nlogn)
Q37
Code not tested
Q38
The key is to change the cyclic judgment condition of binary search.
Q39
Question 2 algorithms are hard to remember
Code not tested
Q40
Clever Method
In C ++, auto & e: v traverses the container. Note that v points to the element reference before changing the value in the container.
Q41
No proof of algorithm is provided in the book, which must be solved urgently
Q43
The method is clever, and the solution is hard to remember.
Q45
The method is clever, and the solution is hard to remember.
Q50
If there is a pointer to the parent node, find the linked list between the two points and find the first public node.
If no, the dfs traverses the linked list of the two points and calculates the first public node.
Reprinted by: Focustc. The blog address is http://blog.csdn.net/caozhk. The original link is opened by clicking
Reading Notes for mathematics Comprehension
Reading Notes: mathematical comprehension-Luo zengru I. Abstract comprehension essence: learning, learning for students, it should not only be satisfied with the learning of superficial texts, but also the spirit of concepts, principles, methods, and so on. In this way, we need to find the answer to the question. This is the basic requirement, but it is not the ultimate goal. If the essence of the mathematical content hidden in the question cannot be revealed after the answer is obtained, it is equivalent to simply repeating the original level of thinking. Knowing the truth, I don't know how to optimize the quality: the main way to optimize the quality of mathematics is to focus on the process of knowledge, such as the process of concept formation, the process of Theorem discovery, and the process of proof. For solving problems, analyzing the problem solving process is a shortcut to optimizing the quality. Looking back, we have provided us with guiding experience. After all, learning mathematics is different from learning technology. A skill can be mastered through imitation and repeated drills. Mathematical Problem Solving is not a mechanical repetition of basic mathematical knowledge and basic mathematical methods, but also the comprehensive and flexible use of these knowledge and methods, it is essentially a creative process of thinking. Later, we realized a way to understand the idea of solving problems by learning the unknown, analyzing the problems that have been solved, and using the idea of solving problems to control knowledge and methods. This experience and method frees us from pure imitation and simple repetition at the same level of thinking, so that every day's learning can be improved by the ability to solve problems or the level of thinking. We believe that, in order to improve the mathematical ability, at least before finding a better solution, "analyzing the problems that have been solved" is a common and feasible method. In fact, the acquisition of solutions involves the following "three in one": 1. capture useful information, symbolic information and image information; 2. extracting memory mainly serves as the basis for solving related formulas, theorems, and basic patterns. 3. combine the two into a logical and harmonious structure. Suffering lies in this step. The role of question-making is to consolidate knowledge, enhance memory, and deepen understanding. However, it is more capable of improving, developing intelligence, and training thinking. Psychological Process of solving problems: the more you know, what I don't know is more useful capturing. The extraction and effective combination are external manifestations of psychological activity. It exactly corresponds to three steps in the complex psychological activity process of people: observation Test, Association conversion, and inference proof. The simple meaning of Lenovo conversion is to classify the problems to be solved or unsolved into a type of problems that have been solved or are easier to solve. Einstein said: What you can observe depends not only on your naked eye, but also on what kind of thinking you use. Thinking determines what you can observe. For example, the Lubin double-off graph G. polia: designed for junior high school students: design their own problem-solving tables to adapt to different stages of different disciplines and learning analysis: the difference between the conditions and conclusions of a question becomes the essence of the objective difference in solving a problem. Design a process of decreasing the objective difference. By constantly finding the objective difference and reducing the objective difference, we can complete the thinking method of solving the problem, to become a difference analysis method, start with finding the target difference. What is unknown? What is known? What are the links and differences between the two? Specialization: mathematicians believe that, when discussing mathematical problems, the specialization is more important than generalization. The specialization problem may be simpler and easier. The function of extension is as follows: 1. breakthrough in solving the problem, 2. Strategies for solving the problem, 3. Methods for completing the problem solving process are generally reduced to special, from complicated to simple, from abstract to specific, and from overall to partial, return to the original place without losing importance, and return to the problems you will do and can start to combine the number-form: the number of two-blade likes is converted into shape, seeing through the essence if a specific problem is converted into a graph, the idea will grasp the problem as a whole, and be able to creatively think about the solution of the problem and convert it into a number: if forward derivation is difficult, reverse lookup is performed. If the problem is solved directly, it is indirectly solved. If the problem is confirmed positively, the opposite is rejected. If the possibility of inquiry is difficult, it is impossible to explore, equations prove that from left to right is not smooth, from right to left inverse method, inverse method, inverse example, constant variable transposition, inverse method of formula theorem: from unknown, find notice, moving closer to the known proof method is more suitable for negative problems, infinite propositions, Uniqueness propositions ,...... remaining full text>
I am a programmer. I will go to the interview tomorrow.
1. The second is an in-depth inquiry on the basis of the first one. For example, the activities and projects on your resume will be further asked;
2. Ask other questions to determine whether your values and world view match the company's;
3. In fact, you have to look at the company. Some companies can perform interviews many times or even, so the content is different.
In short, let's make changes at random! Good luck!