ACM Learning Report

Source: Internet
Author: User

ACM Learning Report

Objective:

The

"Nervous stimulation" of the big semester will soon be over! From the initial contact c++ Now it's almost there. 1 year time. In the freshman semester, c++ Most of the basic knowledge of class is in the Span style= "Font-family:calibri" >c language, in order to master these basic knowledge, fee old let us do a lot of exercises. In fact, I think, these exercises can also be regarded as acm acm The problem is how difficult!! To tell the truth, in the last semester to do the problem is very easy, it is also feel acm It is difficult to get there, so I follow the footsteps of the far, no hesitation elective the ACM Program Design This course, the result, the topic first gave us a dismounted Granville!

Topic one of the content is greedy algorithm, for the first contact with ACM We are more difficult. But at that time did really very exciting, then the course is very much, as if only Wednesday afternoon can take out a relatively long time and then soak in the computer room to do a problem, to make a problem to need a long time, but can make it very happy. But the problem also comes, Learning ACM need too much time, and good to spend a lot of energy, and I this person's biggest shortcoming is no perseverance, so slowly, to ACM study also Slack, It's not special to take it to heart.

Topic Two of the content is deep search and breadth search, this topic did not learn, knowledge simple know when to use what search, but the topic do too little, practice enough, and then incredibly did not score.

Topic Three is the dynamic planning, this topic is good, learned a lot of knowledge, but the problem about the map is not how.

Topic four is about "figure", and all kinds of pictures have confused me. This topic is the most difficult topic, but the topic of the knowledge points can be used to solve a lot of practical problems, such as our current curriculum design work has a 12306 program, in the query the function of the train can use it, moreover, I think, The automatic search function in computer games is related to these algorithms (minimum spanning tree, and check set, etc.), so this part is very important, although now do not understand, but must learn later!!

Knowledge Points:

Then is the Knowledge Point in ACM, the content is mainly courseware:

First, STL basic knowledge:

1, Stack is an advanced (first in the last out , FILO) data structure, it has only one exit, can only operate the topmost element.

Header files : #include <stack>

Definition:stack<data_type> stack_name;

such as:stack <int> s;

Operation:

Empty ()-- returns the bool type, indicating whether the stack is empty (S.empty ())

Size ()-- Returns the number of elements in the stack (s.size ())

Top ()-- Returns the value of the top element of the stack (S.top ())

Pop ()-- removes the top element of the stack (S.pop ();)

Push (Data_type a)-pushes an element a into the stack ( s.push (a);)

2. Queue is a first-in-A-class data structure that joins elements from the bottom and extracts elements from the top

Header files: #include <queue>

Definition: Queue <data_type> queue_name;

such as: Queue <int> Q;

Operation:

Empty ()--Returns the bool type, indicating whether the queue is empty (Q.empty ())

Size ()--Returns the number of elements in the queue (Q.size ())

Front ()--Returns the next element in the queue (Q.front ())

Back ()--Returns the last element in the queue (Q.back ())

Pop ()--Removes an element from the queue (Q.pop ();)

Push (Data_type a)--place an element A into the queue (Q.push (a);)

3, Upper_bound and lower_bound

Upper_bound (begin, end, value);

Returns the first position of an element that can be inserted into value.

Lower_bound (begin, end, value);

Returns the last position of an element that can be inserted into value.

Num[] = {1,2,2,3,4,5};

Lower_bound (num, num + 6, 2) is num + 1

Upper_bound (num, num + 6, 2) is num + 3

4.map and multimap

M.size () returns the container size

M.empty () Returns whether the container is empty

M.count (key) returns the number of elements that have a key value equal to key

M.lower_bound (Key) returns the first position of an element with a key value equal to key

M.upper_bound (Key) returns the last pluggable position of the element with the key value equal to key

M.begin () returns a bidirectional iterator that points to the first element.

M.end () returns a bidirectional iterator that points to the next position of the last element .

M.clear () tells the whole container to be emptied.

M.erase (elem) removes all elements with a key value of Elem , and returns the number, which is not 0 for map 1.

M.erase (POS) removes the element at the point where the iterator Pos refers.

Direct element Access:

M[key] = value;

If there is no element with key value in the lookup, a new element with key value is inserted , the real value is default ( general 0) .

M.insert (Elem) Inserts an element elem

A) using value_type Insert

Map<string, float> m;

M.insert (Map<string, Float>:: Value_type ("Robin", 22.3));

b) use of pair<>

M.insert (pair<string, float> ("Robin", 22.3));

c) use of Make_pair ()

M.insert (Make_pair ("Robin", 22.3));

Second, greed:

1.What is greedy algorithm?

In the process of solving the problem of optimal solution, according to some greedy criteria, starting from the initial state of the problem, the optimal solution of each step is directly obtained, and the optimal solution of the whole problem is obtained through several greedy choices, which is the greedy algorithm.

It can be seen from the definition of greedy algorithm that the greedy algorithm is not considered as a whole, and the choice made is only a local optimal solution in some sense, and the problem's own characteristics determine the optimal solution by using the greedy algorithm.

2, how to use greedy algorithm?

If a problem can be solved in several ways at the same time, the greedy algorithm should be one of the best choices.

In other words, the basis of greedy algorithm is the whole part, and the optimal solution of the whole is obtained by the optimal consider of each part. Although the greedy algorithm is a very concise method, but does not guarantee that all problems are effective, so the use of greedy strategy to solve problems, need to resolve two questions:

(1) Whether the problem is suitable for solving with greedy strategy;

(2) How to choose the greedy standard to get the best / better solution of the problem.

3. For example:

The more classical examples of greedy algorithms should be considered as the type of time, and then the basic question will extend to many other types of topics, such as the first one in the topic:

In topic one, the first move table (ACM Company A corridor north and south of the two sides of the Room, the table from one room to another room, each aisle can only be moved once a table, spents 10 minutes. Move n times table, ask for the shortest time of the question frightened me a jump, that is the first time with the greedy algorithm, or is very unfamiliar, oneself thought already understood in the class school thing, but in the actual operation but made the difficult, still reflects oneself to the greedy algorithm understanding is not profound. The first time to read this question, it is easy to understand, so write the code is very brain-free, and then read several times the topic finally understood a part, but there is a difficulty with it, has not dealt with it, tangled up the old long period of time, to refer to the code of Nonmammalian, found that he set a very magical filter variables, Then I took out the courseware to review a bit, then only to understand how to use the greedy algorithm to arrange the time. Then here's the idea:

Then my train of thought, a total of four rooms , but because they are on both sides of the corridor, so in the corridor in the same location of the north and south of the two rooms can also be seen to make a room, so the room can be re- numbered $ room. First, the input groups of data by the small room number arrangement, in the input of a set of data to pay attention to small room in front, large room after, each room number minus 1 divided by 2 to generate a new room number, After that, the greedy algorithm can be used to solve the problem. A filter variable is set at the time of solving to filter each group of data multiple times. First filter first, the room group that does not intersect is filtered, and the filter variable is zeroed to control that the next filter does not operate on the filtered room group, time is ten minutes, and the second pass filters the remaining room groups for selection. Continue to select disjoint room groups, time ten minutes, and then continue with the third filter until all the room groups are filtered to complete. The final output, and then end. In general, it is a multiple screening of all cases, each time the most eligible conditions are filtered out until all the conditions are filtered out.

Three or two-method search algorithm, three-point basis:

1, two points:

Simple definition: Find elements in a monotonous and ordered set, each time dividing the set into left and right parts, determining which part of the solution is in and adjusting the upper and lower bounds of the set, repeating until the target element is found.

The first contact dichotomy is the root problem in mathematics class, when the teacher joked with us that you should learn the computer should be compiled a two-way program to try, and then, now really used.

Core code (Template):

Long Long res,mid;

while (Low <= high)

{

Mid = (high + low)/2;

if (judge (mid))

{

Low = mid + 1;

res = mid; The final result is res

}

Else

{

High = mid-1;

}

BOOL Judge (long long mid)

{

Long long p = 0;

for (int i = 0; i < n; ++i)

{

p + = Size[i]/mid;

}

return P >= F;

}

For the binary algorithm, as long as the template is remembered, the problem is basically solved;

2, three points:

When the extremum of a convex or concave function needs to be demanded, the solution can be approximated by the three-way method when the expression of the function itself is not easy to solve.

The three-part method actually uses two dichotomy, and takes an intermediate value between mid and left or right:

Definition of a similar dichotomy left and right

Mid = (left + right)/2

Midmid = (mid + right)/2;

If mid is near the extreme point, right = Midmid;

Otherwise ( i.e. midmid near the extremum point ), then left = mid;

Core code (Template):

Double Mid, Midmid;

while (Low + EPS < high)

{

Mid = (low + high)/2;

Midmid = (mid + high)/2;

Double cmid = cal (mid);

Double cmidmid = cal (Midmid);

if (Cmid > Cmidmid)

High = Midmid;

Else

Low = mid;

}

Double cal (Double x)

{

Return (H * d-h * x)/(d-x) + x;

here to put the required function;

}

Four, search:

1. Breadth Search:

Basic idea: Start with the initial state S and use the rules to generate all possible states. constitute the next layer of nodes, check whether the target State G, if not present, on the layer of all state nodes, the order of the use of rules. Generate the next layer of all state nodes, the level of all state nodes check whether G, if not, continue to the above thought to generate the next layer of all state nodes, so that a layer down. Until the target State is present.

Specific process:

1 each time the first element of the queue is removed (initial state) for expansion

2 and put the expansion of the feasible state into the queue

3 Deleting the initial state

4 continue with the above three steps until the queue is empty.

2, Depth first:

Basic idea: From the initial state, the use of rules to generate a search tree next layer of any node, check whether the target State, if not appear, in this state using rules to generate another layer of any node, and then check, repeat the process until the leaf node (that is, cannot regenerate into a new state node), when it is still not the target State, Go back to the previous level and take another branch that might extend the search. Use the same approach until the target State is found.

Specific implementation process

1 Each time you remove the top element of the stack, expand it.

2 If the top element of the stack cannot continue to expand, eject it from the stack. Continue with the 1 process.

3 Repeat until you get the target state (get a workable solution) or the stack is empty (no solution).

Five, dynamic planning:

What is dynamic planning?

(a) Dynamic programming is a method to solve multi-stage decision-making problems.

Multi-stage decision-making: if the solving process of a class of problems can be divided into several interrelated phases, it is necessary to make a decision at each stage and affect the decision of the next stage. The multi-stage decision-making problem is to choose an optimal strategy among the strategies that can be selected, so as to achieve the best results under the predetermined standard .

The individual thinks that the dynamic planning is the combination of greed and search, and divides the whole problem solving process into several stages, each of which chooses the optimal decision on the basis of the previous stage, and then influences the choice of the final result.

2 Principle of optimality:

Regardless of the initial state and the first step, the remaining decisions form an optimal decision sequence relative to the new state created by the previous decision. The sub-sequence of the optimal decision sequence must be the local optimal decision sub-sequence. It is not the optimal decision sequence to include the decision sub-sequences with nonlocal optimality.

2 The guiding ideology of dynamic planning:

In each step of the decision-making, the list of various possible local solutions, according to a certain criteria, discard those who must not get the best solution of the local solution, each step is optimal to ensure that the global is optimal.

2 basic models for dynamic planning:

1, the problem has multi-stage decision-making characteristics.

2, each stage has corresponding "state" and the corresponding, the amount of the description state is called "state variable".

3, each stage is faced with a decision, the choice of different decisions will lead to the next stage of different states.

4. The optimal solution problem of each stage can be attributed recursively to the optimal solution of each possible state in the next stage, and the problem has the exact same structure as the original problem.

2 Several concepts of dynamic planning:

Stage: the phase of solving the problem according to spatial order or time order.

State: Describe the nature of things, different things have different properties, and thus use different states to portray. The description of the problem's solution state is staged.

Decision: A selective operation for each stage according to test instructions requirements.

State transition equation: A mathematical formula is used to describe the evolution law of the state associated with the stage.

The state transition equation is the most important part of the whole dynamic programming, the core of the whole code is this part, the function of this equation is the decision of a certain stage, that is, select the role, choose the most suitable for this stage decision.

2 General steps for solving dynamic programming problems

1, judge whether the problem has the best sub-structural properties, if not have the dynamic planning can not be used.

2, divide the problem into several sub-problems (phased).

3, establish the state transfer equation (recursive formula).

4, find out the boundary conditions.

5. Bring the known boundary value into the equation.

6, recursive solution.

(b) Dynamic programming is actually an algorithm to eliminate duplication, and more specifically, dynamic planning is the use of space for time.

A classic example of dynamic programming is the Fibonacci sequence. Before the ACM had done a few questions about the Fibonacci sequence, at that time felt that such a problem is too magical, as long as there is an equation, all the results are out, and now finally understand the principle of the stairs, take the question "there is a staircase a total of M level, at the beginning you in the first level, if you can only step up one or two levels, to go to the M level, how many ways to go? "For example, want to go to the nth layer, just take a step on the n-1 layer, take two steps on the n-2 layer, so the total result is to go to n-1 layer of walk and walk to n-2 The layer of the walk only and then the result comes out, so his dynamic transfer equation is: Dp[n]=dp[n-1]+dp[n-2] .

Vi. Fig.:

The final topic is on the graph, this topic is a bit difficult for me, just understand a very small part, so in this is not written.

Summary:

ACM Learning Path is full of thorns, but I because of their inertia, lost a great opportunity to realize their own value, although the ACM is not so good, but still some harvest! Continue to work hard in the future!

Note: The knowledge points are taken from the courseware of the old fee.

ACM Learning Report

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.