HDU 1729 Stone Game (SG function)

Source: Internet
Author: User

Some boxes are provided with limited capacity and initial capacity. Each time a stone is added to a box.
The added quantity must be less than or equal to the existing quantity in the box.
It seems like Wythoff Game. Of course it must be more complicated than that.
If the upper limit is S and the current capacity is C, if C + C * C <S & (C + 1) + (C + 1) * (C + 1)> = S, then (S, C) is obviously a defeat
Because no matter how much you get at a time, you cannot directly win, and the other party can directly win.
Then, recursively calculate the C state.
If the maximum defeat T> the current C, then find the C followed by the minimum, that is, the S-C
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <cmath>
# Include <algorithm>
# Define N 10005
# Define LL long
# Define inf 1 <29
# Define eps 1e-7
Using namespace std;
Int get_sg (int s, int c ){
Int q = sqrt (double) s );
While (q + q * q> = s)
Q --;
If (c> q) return s-c;
Else return get_sg (q, c );
}
Int main (){
Int n, cas = 0;
While (scanf ("% d", & n )! = EOF & n ){
Int s, c;
Printf ("Case % d: \ n", ++ cas );
Int ans = 0;
While (n --){
Scanf ("% d", & s, & c );
Ans ^ = get_sg (s, c );
}
If (ans)
Puts ("Yes ");
Else
Puts ("No ");
}
Return 0;
}
Author; ACM_cxlove

Related Article

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.