Test instructions: A game has n rounds, there is a and B races, who wins in the first round, I get I, give x, Y, ask A to be ×, B to Y is not possible, if there is, output a at least the number of won
Problem Solving Ideas:
First Judge N (n+1)/2 = (x+y) Whether there is a solution, that is, the existence of n is an integer, so that all fractions and add up to x+y, that is to Judge n2+n-2 (x+y) = 0, there is an integer solution,
According to the root of the two-order equation ( -1±δ)/2 is an integer, wherein δ=√ (1+8 (x+y)), that is to determine whether the 1+8 (x+y) can be prescribed and Δ is an odd number (if Δ is even, the root is not an integer)
If the preceding conditions meet, in the greedy, starting from N to accumulate the value is greater than the X position, the number is a minimum number of wins, if x<n, then as long as the score is X, the win, that is, X
Long Long Findminimumvalue (long long x, long long y) { long long score = 1 + 8* (x+y); Long Long tmp = sqrt (score); if (tmp*tmp! = Score | | tmp%2 = = 0) return-1; else{ long Long n = (tmp-1)/2, res = 0; if (x <= N) return res; for (int i = n; x > 0;---I) {x-=i;res++;} return res; } }
TopCoder SRM 639 Div.2 alicegameeasy