30th Annual ACM/ICPC World Finals Problem Resolution _ algorithm

Source: Internet
Author: User
Tags ticket

The 30th session ACM/ICPC World Finals topic analysis

Stanford University Wang

Please see http://icpc.baylor.edu/icpc/Finals/2006WorldFinalProblemSet.pdf for the title of this contest.

Problem A

The main idea is, give some tickets, each ticket is a route, such as City A-> City b-> City k->...-> City N, and each ticket has a price. We can use only one part of the ticket, such as City A-> City B-> City K, and then discard this ticket. But there are two conditions, first, the ticket must be in the beginning of the city to use air tickets, that is, we can not use the above ticket from City B to City K; second, if you use the part of a ticket, you will not be able to use the rest of the section.

Now we have a route to visit a series of cities in a sequential way. Give all the tickets you can buy, you can buy unlimited tickets for each ticket, and ask how you can complete the journey with minimal cost.

The data on this subject is quite small, with a maximum of 20 tickets, and each ticket has a maximum of 10 cities. Because the ticket can be purchased repeatedly, the city must be in order, it is easy to think of dynamic planning. But as you can see from the game, countless teams are stuck with the problem and few teams can pass it at once. The problem is not only to access the cities on the specified path, but to access some of the auxiliary cities to reduce the cost. So, we're going to use a two-tuple (I,J) to represent a state. Where I represents the number of cities that have been sequentially accessed on the specified path, J represents the current city. Through the ticket information, it is not difficult to get between the state of a map, and we are asking is actually a shortest path. Notice that the graph is circled, so we can't use dynamic programming directly, but we need to use the shortest path algorithm. At the beginning of the point of view that the scale is very small, at this time can be found to have 20*10=200 a city, a total can have 10*200=2000 state, or quite large.

Conclusion: It is not complicated to understand this problem. But the game must keep a clear mind, analysis of the question, you can successfully solve this problem. Although a lot of teams to do this problem, but very few teams to do the right, there are some teams have been trapped in this problem, can be seen in the competition team generally nervous, not careful to consider.

Problem B

Typical minimum cost maximum flow, not much said. Binary graph matching is also possible, but the resulting graph is too large.

Problem C

Physics problem, I'm afraid I still need a lot of computational geometry. No one did it during the game and I didn't look at it carefully.

Problem D

The main idea: the number of the shape such as a...ab...b is called bipartite numbers, such as 1222,333999999,50,8888,1 and so on. Give a number x (x<=99999) to find the smallest multiple of x n=kx (k>1), so that N is bipartite.

This is a relatively tricky topic. The easy way to think of this is that the bipartite number with a length of P is very limited, with a maximum of p*9*10, which can be enumerated until you get a multiple of x. But in a programming experiment, it turns out that there are times when there are no multiples of x in the thousands. The main problem is that if the end of X is 0, then the end of N must also be 0. such as x=99990, then n will form like aa...a0, and Aa...a is a multiple of 9999, at which point there is only one degree of freedom, so we can expect the length of the answer to be O (x). At this point, if we also use the enumeration of all bipartite number methods, it is possible to enumerate 90* (9999^2)/2 numbers, which cannot be accepted in time.

The solution to this problem is to see that the end has been identified, so we just need to enumerate the previous section, which can be done in O (x) time, acceptable. But there is another problem, the end of which is a few 0. One might think that at the end of X there are several 0,n at the end of the same number of 0. This is wrong. Consider x=250 that any number of shapes, such as a...a0 (a>0), is not a multiple of 250. Because a can only be equal to 5, and 55 is not a multiple of 25. So, the end of N may require more than 0. It is not difficult to find that if the end of x 0 are removed or multiples of 16 or 25, then we need more than 0. And when X is a multiple of 2,4,8, or multiples of 5, an additional 0 is not necessarily necessary, but it may make the solution smaller. At this point we need to enumerate the number of 0, but the maximum enumeration of 3 cases, time is completely acceptable.

When x is not a multiple of 10, bipartite number can be seen as evenly distributed over the remainder of X, at which point we can expect to get the solution in the time of O (x). As I've programmed, it takes almost no time for a direct enumeration of x that is not a multiple of 10. However, in order to ensure that the minimum solution is obtained, you must pay attention to the order of the enumerations.

Summary: A very test of the overall quality of the player's topic. Rigorous mathematical analysis, the processing of various details, as well as programming to achieve the skills are very necessary. Although the above analysis is very long, once you think clearly the program can write very short.

Study questions: Why such a bipartite number must exist.

Problem E

Topic: Give a 01 string and a compression method: Replace all consecutive 1 with its length binary representation, as long as such substitution can shorten the string. For example, 1111101110010 will become 1010110010. Now give the compressed string (length <=40), and compression before the string length (<=16000) and the number of 1, ask whether the decoding method is unique.

can be dynamically planned. Although the number of 1 in the original string may be many, the number of 0 is up to 40. So the state is most 16000*40*40, and most of these states do not appear. It is important to note that the original string is not only to ensure that the number of 0 and 1 is correct, but also to ensure that the compressed fragments are compressed.

The scale of the problem is not large, you can also consider searching. This requires some pruning. There are many ways to prune this problem, but it is not easy to get the correct result within the time limit.

Problem F

I do not understand the problem, do not know how to fit the gear. The feeling is to search or solve the problem of the equation. There was no one to do the game and no one was right.

Problem G

The main idea: Jack took a bunch of people to the pilgrimage. Jack is in charge of money, he will encounter four kinds of operation: Pay,collect,in,out. Pay is to pay a certain amount of money, collect is from let each person pay a certain amount of money, in is new to join a number of people, each person to pay the current total amount/Current total number of so much money. Out is to leave a number of people, each taking away the current total amount of money/current total number. Note that in and out, the average amount of money per person may appear as a score. The title says, assuming that Jack is lucky, every time he's just finishing it, ask him how many people he may have started with.

The problem looks bad, but we can analyze it seriously. It is not difficult to find that the problem is only in and out of the two operations. Assuming that for the first time in or out (suppose to be in P), we have n individuals, the average person's money is k, then in P, we have n+p individual, each person's money or K. The collect operation does not affect the current divisibility. Suppose that the next two operations are pay Q and in T, then pay Q has n+p individuals, and everyone's money is k-q/(n+p). This must be an integer, because the next operation is in. So the n+p must be the divisors of Q, so that n can only have a finite number.

It is not difficult to conclude from the above analysis that if we call in and out the critical operation, the problem has a finite solution if and only if there is at least one pay operation sandwiched between the two critical operation.

We can repeat the steps above to combine the pay of all successive critical operation (note that the collect operation has no effect on the divisibility), and then draw a series of divisibility, each of which is a form (n+a) |b. There is no need to solve the whole system, n must be an approximate divisor of the b-a, so find all the divisors of an equation and then substitute it for other tests.

This algorithm seems too simple, there should not be so few teams in the game to do the right. There may be some places I have not considered, you may wish to correct.

Problem H

It seems to be a troublesome origami problem and no one is doing it during the game.

Problem I

Send the question. Find the longest one in the 22 shortest circuit. Simple Floyd algorithm, put in TopCoder absolute 5 minutes a bunch of people to do it.

Problem J

Topic: Give a direction graph and two point s1,s2, and find a subset of the smallest vertex, so that the two points in the subset induce of each other to reach each other.

In fact, we can see that we have to choose two paths, one from S1 to S2, the other from S2 to S1, which minimizes the number of vertices on the path. First, S1 and S2 must be in a child set. Let S (V1,V2) represents the number of vertices that must be selected for V1,V2 strong connectivity, except V1,v2, D (V1,V2) represents the shortest path of the bundle V1 to the V2, then obviously S (v1,v2) <=d (v1,v2) +d (V2,V1)- 2, because if the two shortest paths do not have coincident vertices, then the total number of vertices that appear is D (v1,v2) +d (V2,V1)-2. Consider the case of overlapping vertices, suppose that there is a point T in the middle, then to let v1,v2 strong connectivity, we can let v1,t strong connectivity and t,v2 strong connectivity, so S (V1,V2) <=s (v1,t) +s (v2,t) +1. If you let T=s (V1,V2) +1, then T (v1,v2) <=t (v1,t) +t (v2,t). Doesn't it look familiar to you. This means that we can think of T (V1,V2) as a shortest path between v1,v2.

So the algorithm becomes clear, first using the Floyd algorithm to find D (i,j), then let T (i,j) =d (i,j) +d (j,i)-1, and then the Floyd algorithm to update the value of T (I,J), the final answer is T (S1,S2) +1. The main part of the entire algorithm does not exceed 10 lines of code.

Summarize:

A,b,d,e,g,i is a "better to Do" topic, J is a strong algorithm for a graph proposition, the remaining three questions are not difficult to say, but at least not conventional. Final in the people are very cautious, not easy to do an unconventional problem, and will not easily do other people did not do the problem. Although the final champion is 6 questions, but I think if some teams actually have to make 7 problems of strength. Final such game, still very see play.

A,b,d,e,g,i These 6 questions, I belong to the question, B is the basic problem, a has a little trick, but also should do the right; d,e a bit complex, each has some traps, but also belong to the right topic. G As long as careful analysis is actually very simple. If you come up with an algorithm, it's only 5 minutes to write the program. Of course, it's much more difficult to do that in a game than an outsider who has no pressure to analyze it.

The remaining c,f,h three questions basically nobody does, I now do not have too much time so also did not look, if someone has the idea, please say it out.

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.