2011 February Bronze

Final Results          

                 -- case number --
            1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
dance2      *  *  *  *  *  *  *  *  *  *
hexagon     *  x  *  x  x  *  x  *  *  x  x  x  x  x  x  x
treats      *  *  *  *  *  *  *  *  *  *


Time allocation: It
took about half an hour to read the questions. The first question was a bracket matching question , the second question was a mock question , and the third question was BFS . The general idea is there, and then I start to write the program.
The most difficult of these three questions should be the third question, so I decided to do the third question first.

 

The third question: Hexagon
difficulty 1: How to save this table
can only be saved in an array, just sink all the grid points in the figure, like an array of small houses;

Difficulties 2: How to achieve the corresponding numerals in FIG
used to achieve the pre-mapping between the coordinates and digital array

Difficulty 3: How to find the connected edges
should be considered carefully, because the boundary conditions are a bit complicated.
There are at most six connected points, and they can be calculated separately.

Difficulty 4: How to deal with the situation where the left and right are adjacent to each other. The
specific contact picture in the topic should be divided into three situations. When doing it, I wanted to be lazy and merged the middle to both sides, but it was not right. After the make-up Only found out later.

 

Question 2: Treats
Difficulty 1: There are
more textual descriptions of the title , so be careful not to miss the details;

Difficulty 2: How to realize that
if you find the largest one that has not been picked every time, the time cost is too large, reaching O(n^5);
you can also sort them, from largest to smallest, but it involves saving The problem of the table, to restore the information back, I used space for time, opened two arrays of 1,000,000, and mapped back the coordinates corresponding to the value; because the table is dynamically exchanged, the two Large arrays should also be updated dynamically, but fortunately, it is not difficult to update; the final issue is how to exchange. Because of the row priority, you must first find the rows that can be moved forward to exchange, and then find the columns that can be moved forward to exchange; Based on the fact that each time it must move forward, the occupied rows and columns must be continuous, so save a pointer to the smallest row and column that can be exchanged currently, and you can judge whether the exchange can be performed, but this pointer also needs to be dynamically updated. Some points may not need to be exchanged, but they will also occupy the corresponding ranks;


Question
1 : Dance2 Difficulty 1: Efficiency
If you are honestly to split a pair of brackets, the programming complexity is higher, and it may be better to use pointers; but the time efficiency is relatively low;
because there is no requirement for the question So you can use some properties of parentheses. Because the form of parentheses is <> (>< in the title), the number of <will not be less than the number of> anywhere, otherwise you can only go to> The direction of <has developed; if the number of the last two directions is the same, there must be a scheme that can be matched (proof???)

As for the proof, you can use mathematical induction:
(1) When there are n = 1 pairs, it must be <>, and there is a pairing scheme;
(2) Assuming that when n = k pairs, there is a pairing scheme;
when n = k+ 1 is, it is easy to know that the first and last must be <, and the first> is found at position i from left to right, then 1 —— i-1 are all <, and i-1 and i are paired, and the remaining The string of still meets the requirements given before, and there are k pairs. From (2) we know that there is a matching plan;
(4) In summary, there must be a matching plan that meets the above conditions.

 

Experience:
1. It is very important to create data to find BUG;
2. Add COMMENT before a section of the program will make the program thinking much clearer;
3. Slowly adapt to using intermediate results to block the correctness of the program;
4. Large array Put it outside the main function, and put the rest in the main function as much as possible, and the loop variables are declared in the loop body;
5. Be confident, don'tsaywhy you can't prove it, the proof of the first question is still within the scope of ability, and you must try;
6. The data range is still not careful, you should be stuck in the estimation, you should not put the estimation, and finally add some points appropriately; sometimes it is an order of magnitude estimation error;
7. If <> else <> nesting, be careful to forget the else

 

 

My Code

hexagon.cpp

treats.cpp

 

dance2.cpp

  

 

Guess you like

Origin blog.csdn.net/zjsxzjb/article/details/6175293