June good record title

Codeforces 1166C A Tale of Two Lands

[Absolute value Problem Given a number of columns, find which satisfies \ (min {| x + y |, | xy |} \ leq min {| x |, | y |} \) and \ (max {| x |, | y |} \ leq max { | x + y |, | xy |} \) number of \ ((x, y) \ ) number.

\ (x, y \) symbol require classification discussion, it seems a bit complicated. Afterwards understand the symbols in this question is not affected.

We can consider. For two positive numbers \ (the X-, the y-(the X-<the y-) \) , if the change does not affect only the symbol \ (| x + y | \ ) and \ (| xy | \) value, then we would not have considered symbol. Then we only need to prove that \ ((x, y) \ ) and \ ((- x, y) \) value reached the same on it. In this case, once \ ((x, y) \ ) holds, then \ ((- x, y) \) and \ ((x, -y) \ ) also holds, then \ ((- x, -y) \) was established. That is, once \ ((x, y) \ ) holds, then \ ((| x |, | y |) \) was established. This proved that it is also easy. When the logarithm of \ ((x, y) \ ) when, \ (| X + Y | = X + Y \) , \ (| XY | = YX \) . When the logarithm of \ - ((x, y) \) when, \ (| + the -X-Y | = YX \) , \ (| -XY | = X + Y \) . It proved.

This mathematical proof often do not bother to discuss classification. Since \ ((x, y) \ ) and \ ((y, x) \ ) are equivalent, so long as it proved one.

AtCoder Beginner Contest 126 D. Even Relation

[Problem] The parity tree to the node in claim staining (0/1) of a tree, if two nodes requires the same color, the distance therebetween is even.

Two tree nodes \ (u, v \) defines the distance is \ [dep_u + dep_v-2 * dep_ {lca (u, v)} \] so make the distance is even, if and only if \ (dep_u + dep_v \) is even. This iff \ (dep_u \) and \ (dep_v \) the same parity.

Therefore, we only need to calculate the distance to each point of the root is odd or even. Dyed one color all odd and all even another color can be dyed.

In fact, we have a simpler implementation, from one point to the root of parity depends on the distance between the parity of the father and the father of it. So if a father from the point and it is even, the father of the same color, or different colors and father.

Codeforces 437 C. The Child and Toy

[Delete points on the map Erase problem / topological sorting] gives a little right of undirected graph, each time you select a point to delete and delete this point even the edges. To delete a point price is right values ​​all of its neighboring points and at this time. Ask them to delete the minimum total cost of all the points.

Delete points is the essence of the border erase, because in the end all the points will be completely deleted. The contribution of each side must be a point at both ends. Theoretical minimum that each side have opted for a small contribution to that point. This requires that we have for each side the right to delete the point larger point. This is reminiscent of ...... topological sort! We will each undirected edges have changed little even to the point right from the big point right point edge directed edge, can form a \ (DAG \) topological sorting. However, the point may have equal rights might ring, the inner ring has a point does not matter, you can shrink tarjan point. Fortunately, this question does not require an output program. I can think of a question that requires an output program.

Codeforces 1175 C. Electrification

[Answer] is given binary sequence a number line. Seeking a position \ (X \) , so \ (X \) distances to all points in the first \ (K \) small distance as small as possible.

Consider the first-half \ (k \) a small distance. Such problem is that \ (O (n) \) determine the feasibility. And its feasibility if there is a position equivalent to \ (X \) , so \ ([x-mid, x + mid] \) within it can comprise at least \ (K \) points. And a determination \ (MID \) is determined, the problem is transformed into a length \ (2 * mid \) whether to cover at least a section \ (K \) points. A queue can be done with this problem.

Codeforces 1175 D. Array Splitting

[] Gives a maximum value of an expression sequence, to which cut \ (k-1 \) blade becomes \ (K \) blocks. The first \ (i \) values for the block \ (i * \ sum \ limits_ {j∈ a_j block i} \) . Seek maximum total value.

The slope is not optimized DP! \ [ans = max \ {k * (s_n-s_ {k_1}) + (k-1) * (s_ {k_1} -s_ {k_2}) + \ dots + (s_ {k_ {k-1}} - s_ {0}) \} \ ] found to become approximately out \ [ans = k * s_n- \ sum \ limits_ {i = 1} ^ {k-1} s_ {k_i} \] Thus prefix and sort solving It can be.

Luogu 1875 Allison magic potion

[Dijkstra] Thought given \ (n-\) price of an article \ (a_i \) , then give \ (m \) a relationship, a relationship \ (X \) article with a \ (Y \) Item 1 can be synthesized \ (Z \) items. Asked to give a minimum price of 1 items.

Obviously \ (a_i \) minimum that must determine the value for the \ (a_i \) , because the remaining value than the \ (a_i \) large, certainly not by synthesizing excellent. Thus, every time we elect a undetermined value items that a minimum, thus ensuring that it can not be updated.

When we found that the number of statistical programs will be repeated statistics. So every time we make only two determined value items to update others.

A little metaphysics.

Codeforces 1165 E. Two Arrays and Sum of Functions

And minimal sequence [greedy strategy twenty-two product, the problem of covering the count number is given two length] \ (n-\) sequence \ (A \) and \ (B \) , the definition of \ (f (l, R & lt) = \ SUM \ limits_ {L \ Leq I \ R & lt Leq} a_i \ CDOT B_i \) . Seeking \ (\ min \ {\ SUM \ {limits_. 1 \ Leq L \ R & lt Leq \} n-Leq F (L, R & lt) \} \) . ( \ (N-\ Leq 2 \ ^. 5 CDOT 10 \) )

Answer requirements equivalent to \ (\ min \ {\ SUM \ {limits_. 1 \ Leq L \ R & lt Leq \} n-Leq \ SUM \ limits_ {L \ Leq I \ R & lt Leq} a_i \ CDOT B_i \} \) . So we consider for each position \ (i \) , \ (a_i \ cdot b_i \) appears many times in your answer. Some direct statistical difficulties, we may wish to cover point (i \) \ the right end of the interval considered in turn. Right point \ (I \) , the left end point may take \ ([. 1, I] \) ; a right end point \ (J \) , the left end point may take \ ([. 1, I] \) ...... heald on the left end point may take \ ([. 1, I] \) , the right end point may take \ ([I, n-] \) . It is possible to cover the point \ (I \) interval total \ (i \ cdot (n- i + 1) \) th (Conclusion)

The answer can thus be represented in this form: \ (\ min \ {\ SUM \ {limits_. 1 \ Leq I \} n-Leq a_i \ CDOT B_i \ CDOT I \ CDOT (I-n-+. 1) \} \)

The title conditions except \ (B_i \) than are given value, may wish to set \ (= a_i C_i \ CDOT I \ CDOT (I-n-+. 1) \) . The answer is converted into \ (\ min \ {\ sum \ limits_ {1 \ leq i \ leq n} c_i \ cdot b_i \} \)

Multiplying the minimum sum of two on two two sequences, a greedy Conclusion: The two sequences from small to large, \ (B_i \) should match \ (I-n-C_ {+}. 1 \) . (in conclusion)

With any \ (a_i, a_j, b_p, b_q \) satisfies (sorted) \ (. 1 \ Leq I <J \ n-Leq \) , \ (. 1 \ Leq P <Q \ n-Leq \) . There are two options \ (= a_i A \ CDOT b_q a_j + \ CDOT b_p \) , \ (= a_i B \ CDOT b_p a_j + \ CDOT b_q \) , as we compare the size difference method. \ (AB = a_i \ CDOT (b_q-b_p) + a_j \ CDOT (b_p - b_q) = (a_i-a_j) \ CDOT (b_q - b_p) \) , apparently \ (a_i-a_j \ leq 0 , b_q-b_p \ GEQ 0 \) , so \ (AB \ Leq 0 \) , so \ (A \ B Leq \) . So both for cases, select \ (A \) certainly does not gifted, so greedy conclusion holds.

Codeforces 1154 E. Two Teams

[Amortized complexity] gives a doubly linked list of length \ (n-\) in sequence, and \ (P \) operations required to find the maximum value, and then in the transverse \ (K \) th, labeled \ (P \ MOD \ 2 \) . After the diffusion of elements (including the maximum) to delete all. Q mark the end of each element of the case.

It is implemented using a doubly linked list. In which the process can be used to find the maximum heap to maintain, if it has been deleted continue pop. Such complexity must be \ (O (n-\ log n-) \) . Because there is no insert, you can not stack, the direct effect is the same sort.

This question is quite enlightening, this question does not need to seek the minimum segment tree, because the demand is global minimum. The method does not require maintenance strange lengths can be achieved by a doubly linked list, because there certainly will not be marked elements many times. To analyze for problem analysis.

Codeforces 1148 D. Dirty Deeds Done Dirt Cheap

[Thinking,] given the implied conditions \ (n \) on the number of \ ((a_i, b_i) \) . It requires a certain sequence pairs selected to meet the \ (a_ {i1} <b_ {i1}> a_ {i2} <b_ {i2}> \ dots \) or \ (a_ {i1}> b_ {i1} <a_ {i2}> b_ {i2} <\ dots \) Q is selected from a few to up to

Obviously it can be divided into two groups. Let's talk \ (a_i <b_i \) of this. As long as each \ (b_i> a_ {i + 1} \) on the line. If satisfied \ (B_i> B_. 1} + {I \) , then it must satisfy \ (B_i> A_. 1} + {I \) . So we want to follow in just a few (b_i \) \ descending order can be, for all numbers are selected.

What are the conditions to be met without careful analysis Yes. If you can find a careful analysis method. Still have to carefully look at a topic that has the nature of it.

Codeforces 276 D. Little Girl and Maximum XOR

Bitwise] [given \ (L, R & lt \) , seeking \ (max \ {a \ oplus b \} (l \ leq a \ leq b \ leq r) \)

First \ (l, r \) turn binary. Obviously greedy need to start from a high level. In front of the same to ignore, for the first bit different, we found obviously different or achieve 1. Consider the following bits, because the first one has been different, so every bit r can be decreased, l each bit can be increased. So every one can Couchu 1. Then the answer came out.

Codeforces 577 B. Modulo Sum

[] Properties of the modulo operation is given \ (n-\) number, asking whether to select a subset, and that it can be \ (m \) divisible. \ (n \ leq 10 ^ 6 , m \ leq 10 ^ 3 \)

Consider a special nature: \ (n-\) prefix number and the modulo do, as long as obtained according to pigeonhole principle \ (n-> m \) , and then there must be a prefix of the same value. Prefix meaning is the same and the number is between this and \ (m \) divisible - that is the answer. So long as the \ (n> m \) certainly solvable.

Thus restrictions becomes \ (n-\ Leq. 3 ^ 10 \) . Backpack can be. Transfer backpack a little difficult, because you want to avoid zero. At this time wish to use a brush table method. As the need to shift back and forth, you can not do a rolling one-dimensional array.

## Codeforces 552 C. Vanya and Scales

[Questions conversion, binary search gives two numbers] \ (W \) and \ (m \) ( \ (. 1 \ W Leq, m \ ^ Leq 10. 9 \) ), and gives the weights 101 \ (W ^ 0, ^ W. 1, \ cdots, 100 W ^ \) (only one of each by weight). The \ (m \) on the left, now to put some weight around, asking whether it is possible balance.

Each weight can be put on the left, the right place, or hold. I.e. weight coefficient for each \ (\ {- 1,0,1 \} \) , it can be asked whether the sum of \ (m \) . Obviously \ (w = 2 \) must satisfy, from \ (w = 3 \) began to consider, \ (\ ^ log_310. 9 \ approx 20 is \) , thus binary search.

Codeforces 578 B. "Or" Game

And or [,] and prefixes and suffixes a given sequence can be \ (K \) operations, each can take a number in the sequence to a fixed value \ (X \) . After the maximum number of or all operations and ask.

Maximum bit operation again, greedy high to low. 1 wanted to become a high level, try to put \ (x \) ride on the same number. Thus a problem into a number sequence multiplied by \ (X ^ K \) , or the maximum and seeking. Or inverse operation does not seem to exist, it seems not very good maintenance. The correct approach is to maintain or prefixes and suffixes and well. So as to limit the number of each sequence into halves.

Guess you like

Origin www.cnblogs.com/qixingzhi/p/11237089.html