Jiugongge ---- Netease game 2015 R & D pen questions

Source: Internet
Author: User

I have been looking for a job recently. I participated in the R & D test of Netease games yesterday, with a large number of questions and 6 major questions.

1. Minimum lexicographic string,

2. Recursive plot function to non-recursive

3. the data structure 4-tree is commonly used in game programming. There are three questions: how to determine the intersection between the two rectangles In the rectangle? The second question is how to create a 4-tree, the third question is how to find contained objects in the quad-tree based on known rectangular blocks.

4. The KD tree is an English question. Let's look at the complexity of an algorithm. The first question is to analyze the complexity of an algorithm. The second question is to implement the algorithm by yourself (not to mention it)

5. Find the longest path with a weight binary tree. The weight value can be negative.

6. The password is the mobile phone gesture. There are three questions. One question is: If only two passwords are set, how many types of passwords are allowed? The password cannot be crossed. For example, if one or three passwords pass through two, this is not allowed. Second question, if the password is in N * M format, determine whether a two-digit password meets the requirements (the same as 1 is required). Third, if the number of digits of the password is set to 9, the number of suitable passwords, algorithm ideas, and pseudocode.

 

At that time, the last question was written in a hurry. It was written in DFS implementation, similar to full-Arrangement Implementation, except that the non-conforming ones can be eliminated in the recursive process (equivalent to pruning), and the pseudo-code writing is rare, I wrote it on my computer this weekend. Share with you.

Analyze the jiugongge, as shown in.

1 2 3

4 5 6

7 8 9

It is not hard to see that all points can be divided into three types:

1 3 5 9 is a class, 2 4 6 8 is a class, and 5 is a class.

The first type of point cannot be interconnected at any two points. However, if the two points have already been used, they can be interconnected.

In the second type, 2 8 cannot be directly connected, and 4 6 cannot be connected. However, if 5 has been used, they will become connectable points.

The third class has only five vertices, which can be directly connected to all vertices.

 

There are two algorithms on the Internet for full sorting: Recursive Algorithms and non-recursive algorithms. If you are not sure, please refer to Baidu. There are already many Daniel blogs in the blog Park. I will not repeat them here.

I am using a simple recursive algorithm. First, the idea is clear and understandable. In addition, the depth of this question is not big, only 9, so DFS is acceptable.

The Code is as follows:

1 int DFS (int * a, bool * flag, int K, int N) 2 {3 4 int sum = 0; 5 If (k> = N) 6 {7 # If 0 8 for (INT I = 0; I <K; I ++) 9 {10 cout <A [I]; 11} 12 cout <Endl; 13 # endif14 return 1; 15} 16 else if (k <n) 17 {18 for (INT I = 1; I <= 9; I ++) 19 {20 if (! Flag [I]) 21 {// check whether 22 if (check (A, flag, I, k) 23 {24 flag [I] = true; 25 A [k] = I; 26 sum + = DFS (A, flag, k + 1, n); 27 flag [I] = false; 28} 29} 30} 31 return sum; 32} 33}

Array a stores the identified password sequence. The flag array flag [I] indicates whether the number I has been used, and the flag [0] is not used. # If 0 ...... # The endif code segment is used to print out a suitable sequence of passwords.

K indicates that the number of the previous K-1 has been determined and is now ready to determine the number of K that meet the requirements. N indicates the password length. If the two or three passwords meet the requirements, you can set them to the corresponding values.

 

The most important algorithm is the check function, which is to check whether the Password meets the question.

The idea of the check algorithm has been analyzed above. The implementation is provided here. It should be noted that we only need to judge the legitimacy of the combination of the number a [k] and the previous number A [k-1,

Why? Because this is a recursive algorithm, that is to say, the number of the first K-1 constitute a sequence step by step to determine the valid sequence, so you only need to judge from a [k-1] to a [k] is valid. The Code is as follows:

1 bool check (int * a, bool * flag, int I, int K) 2 {3 if (k = 0) // determine the first number, any number is valid 4 {5 return true; 6} 7 if (I % 2 = 1 & I! = 5 & A [k-1] % 2 = 1 & A [k-1]! = 5) // A [k-] and I both belong to 1, 3, 7, 9 8 {9 return flag [(I + A [k-1])> 1]; 10} 11 else if (I % 2 = 0 & A [k-1] % 2 = 0) // A [k-] and I both belong to 2, 4, 6,812 {13 if (a [k-1] + I = 10) 14 {15 return flag [5]; 16} 17 return true; 18} 19 else // other cases 20 {21 return true; 22} 23}

Well, this question has been solved. The question with 22 points is not very difficult, so it is worth analyzing. In addition, we can clearly figure out the total number of gesture passwords ). If it is a cracking attack, it is really easy. The source code of the entire test is provided here.

# Include <iostream> using namespace STD; bool check (int * a, bool * flag, int I, int K) {If (k = 0) // determine the first number. Any number is valid {return true;} if (I % 2 = 1 & I! = 5 & A [k-1] % 2 = 1 & A [k-1]! = 5) // A [k-] and I both belong to 1, 3, 7, 9 {return flag [(I + A [k-1])> 1];} else if (I % 2 = 0 & A [k-1] % 2 = 0) // A [k-] and I both belong to 2, 4, 6, 8 {if (a [k-1] + I = 10) {return flag [5];} return true;} else // other cases {return true ;}} int DFS (int * a, bool * flag, int K, int N) {int sum = 0; If (k> = N) {# If 0 for (INT I = 0; I <K; I ++) {cout <A [I] ;}cout <Endl; # endif return 1 ;} else if (k <n) {for (INT I = 1; I <= 9; I ++) {If (! Flag [I]) {// check if (check (A, flag, I, k) {flag [I] = true; A [k] = I; sum + = DFS (A, flag, k + 1, n); flag [I] = false; // The flag is restored here }}return sum ;}} int main () {# If 0 freopen ("out.txt", "W", stdout); # endif int A [9] = {0 }; bool flag [10] = {false}; int sum = 0; For (INT I = 4; I <= 9; I ++) {sum + = DFS (, flag, 0, I) ;}cout <sum <Endl ;}

The total number of 4-9-bit gesture passwords is 389112. The program runs very fast. If you are interested, you can run it. Is the gesture password really safe? Let everyone think about it!

If you are interested, you can also make a GUI and then look at all the gesture passwords, there must be some domineering!

Jiugongge ---- Netease game 2015 R & D pen questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.