TopCoder SRM 639 Div.2 alicegameeasy

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.