To K concentrations were $ frac {a_i} {1000} $ drink, requires each beverage integer L, against the concentration of $ frac {N} {1000} $ beverage. Seeking at least take a few liters of beverages.
data range
$ 0leq nleq 1000,1leq kleq 10 ^ 6 $
$0leq ai leq 1000,a_i in Z$
practice
By the pigeonhole principle, different concentrations of up to 1001 kinds of drinks.
Let K is the number of different concentrations. Each beverage provided by the xi liters, there
$$
FRAC sum_ {{I = FRAC. 1} ^ {a_i Kx_itimes} {1000} {} {I = sum_ Kx_i. 1} ^ {N} = FRAC} {1000}
$ $
after simplified as
$$
sum_ {I} = ^ Kx_itimes. 1 (N-a_i) = 0
$$
original statute problem: taking the least number from the set $ {N-a_i} $ (each number can take any number of times), so that their is zero.
We vertex and to set even according to the number of edges (if digital $ N-a_i $ set, and from the $ s $ and $ s + (N-a_i) $ connected edge).
Statute problem to: find length from 0 to 0 in the end of the smallest ring. BFS can be.
Optimization: N $ and $ a_i by known range: $ - 1000leq N-a_ileq 1000 $. Therefore, if the presence of start and end points of a ring 0, then we can reconstruct the order of the upper ring, so that each time after an edge, and are in the range [-1000,1000] a. So when we build map, and can range in [-1000,1000] inside.
Time complexity: $ O (E) = O (2001times max (1001, K)) $
Code
|
|
Original: Big Box Codeforces 789E