25 provincial election simulation solution to a problem

A. Ring

Is a very clever construction problems. 

Consider the condition of writing $ s_i, s_ {i + 1} $ must satisfy equation.

Provided $ x_ {i, j} $ $ S_I represents the first $ J $ $ $ 1 to $ locations.

By the operator A has $ k * t + \ sum \ limits_ {j = 1} ^ k x_ {i, j} \ equiv \ sum \ limits_ {j = 1} ^ k x_ {i + 1, j} \ pmod n $ , where $ t $ is an arbitrary integer.

By the operator B has $ 1 + \ sum \ limits_ {j = 1} ^ k x_ {i, j} \ equiv \ sum \ limits_ {j = 1} ^ k x_ {i + 1, j} \ pmod n $.

Available subtract $ 1 \ equiv k * t \ pmod n $, and so $ k $ $ $ n-prime, is a prerequisite for the presence of legitimate programs.

Consider a combination method embodiment constructed directly $ x_ {i, j} = \ dfrac {i + j-1} {k} \ bmod n $.

Easy to find S_I $ $ corresponds to $ s_ {i-1} $ right $ \ frac {1} {k} $ bits, i.e. A operation.

While $ x_ {i, k} = x_ {i-1,1} + 1 $, B corresponds to the operation.

Because relatively prime, $ x_i $ is clearly not heavy.

 

B. DNA Sequence

Consider the optimal solution is $ 1 to $ $ $ n-order come.

The first idea is greedy selected from front to back, and then find a local optimum is not the global optimum, then the dummy.

So consider backwards consideration, because at this time to determine the back, a local optimum is a global optimum.

Data range is very small, you can easily violence.

Correct answer is each string $ S_I $ decomposition of $ X ^ a + Y + 'Z' $, where $ X-$ shortest satisfies $ X ^ {\ infty} <prefix S_I $ a $ S_I $ a, $ 'Z '$ is added to indicate the maximum characters.

These strings are sorted by a first keyword $ X ^ {\ infty} $ ascending order, the second keyword $ Y + 'Z' $ descending.

Probably can be understood, by this approach, each can find a $ X $, then the $ X $ corresponds to a minimum of $ Y $ into the final surface, and the next $ X $ grab position.

In this case, the optimal solution is $ from $ 1 to $ n $ in order to, you can do directly above the greedy.

 

C. Explore

Such customs checkpoints + bonus question there are some good greedy approach.

Into the trees can often be considered by the merger.

Consider some of the special nature of this question, we do not need to complete each level break, just find the mother of ore with minimal cost to get away.

Great benefit assumptions mother mine, then we just need to break revenue - the price> Off 0.

For such problems can be sorted according to expense directly.

That we consider the cost by small to large, as much as possible to make money.

Then consider two cases separately:

1. father node has been selected, then the direct election of the current node.

2. The father node has not been selected, now is not the election of the current node, but for the future to be elected to the current node, the current node and the parent node into one point.

Because it involves the combined operation, in order to determine whether the parent node is selected, and needed to maintain a disjoint-set.

Guess you like

Origin www.cnblogs.com/skyh/p/12328016.html