2019 Summer Hang two day4 test summary

T1

Subject to the effect

Given three integers \ (A, B, C \) , find the number of polynomials have \ (F (x) \) satisfies \ (F. (A) = B, F. (B) = \ C) , coefficients of the polynomial are non-negative integers, if there are an infinite number, output \ (- 1 \) .

sol

I only wrote the examination room dfs violence. In fact, each of the coefficients of the polynomial are less than equal to b, the first sentence out of special circumstances equal to b, and c can be seen as the binary number b (b special sentence equal to 1), calculate the coefficients of the polynomial, inspection \ (F ( a) \) is equal to b.

T2

Subject to the effect

Set \ (F_n \) is the Fibonacci number of \ (n-\) entries, seeking $ \ (GCD (A * F_n + B * F_ {n-+. 1}, C * F_n + D * F_ {n-+ 1}) \) , where \ (1 <= A, B, C, D <= 3,1 ^ 10 <= n-<= 18 is 10 ^ {} \) .

sol

I only write in the examination room of violence and \ (b = d = 0 \ ) is part of the division, I began to think positive solution is very advanced data structure, the result is a very clever use of Decreases Technique, \ (c * f_n + d * f_ {n + 1} \) Save \ (\ lfloor \ frac {c } {a} \ rfloor \) times \ (A * F_n + B * F_ {n-+. 1} \) , to give \ ( C \% A * F_n + (DB * \ lfloor \ FRAC {C} {A} \ rfloor) F_ {n-+. 1} \) , in this way simplifying the original formula can be obtained by \ (gcd (a * f_n + b * f_ {n + 1} , c * f_ {n + 1}) \) form. Can first obtain \ (GCD (F_n A * + B * + n-F_ {}. 1, n-F_ {+}. 1) \) , this is equal to \ (gcd (a, f_ { n + 1}) = gcd (a ,. 1 + n-F_ {} \% A) \) , power can be quickly determined matrix, provided \ (G = GCD (A, n-F_ {+}. 1) \) , then the original formula is equal to \ (g * gcd ((a * F_n + B * F_ {n-+. 1}) / G, C * F_ {n-+. 1} / G) \) , definition of gcd, which is equal to \ (gcd (a * f_n + b * f_ n-+. 1} {, C * G) = GCD ((A * + B * F_n n-F_ {+}. 1) \% (* C G), G * C) \) , again using the matrix to obtain fast results power .

T3

Subject to the effect

Sunny day, a small and small G L playing games, games in a weighted graph \ (\ G = (V, E)) performed on, wherein the total number of points \ (n-\) is even, the point bit right \ (W (V) \) , the right side edge has \ (C (E) \) . Rules of the game is this:

  • Small L and small turns to the point G in FIG stained, small L will vertex dyed black, small G will vertex colored white
  • Each person must give exactly one point per round stained
  • Two people can not ⼀ a point has been dyed coloring
  • In \ (\ frac {n} { 2} \) after the wheel game, each person has a set containing all of his points stained. For vertex set \ (S \) , the resulting score is the right point and the plus subgraph (i.e. endpoints of these two points and all points within the edges of the sub-set configuration of FIG.) And the right sides.

In the ladies first gentleman, please small L G small stain first. Two PORTRAIT want to make your score more than the other, and the more the better. L G small and small are very smart, the game will use the best strategy. Clearly the last two points is uniquely determined, seeking the ultimate small fraction of G L minus a small fraction.

sol

This problem is not zero outObviously I was zero. I began to think a wrong greedy. Figure right to have a bit annoying right side, I put each given a point value for the right point and the right side and connected to it. Every election the maximum points apiece. The results are not a sub.

Correct answer iscorrectgreedy. Set \ (F \) is the fraction of small G-L is reduced scores for each edge, discuss color across it, if all white, the white point corresponding to each \ (F \) contributed \ (\ {{2}. 1 FRAC} \) , if all black, black spots corresponding to each pair of \ (F \) contributed \ (- \ {2}. 1 {FRAC} \) , if a black and white, rather the black point \ (F \) contributed \ (- \ FRAC. 1} {2} {\) , the white point \ (F \) contributed \ (\ FRAC. 1} {2} {\) . Therefore still a priority value to each point, and the right side of the right point and its associated \ (\ huge \ frac {1 } {2} \) and. The maximum value per each election point, \ (F \) decreases the priority value L is preferentially selected points of the selected G value smaller dots. Time complexity \ (\ Theta (nlogn) \) (sorting).

Guess you like

Origin www.cnblogs.com/hht2005/p/11402665.html