Hdu3980 Paint Chain ------ sg ring -- Chain a row of stones into several heaps

Source: Internet
Author: User

Paint Chain
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 696 Accepted Submission (s): 252


Problem Description
Aekdycoin and abcdxyzk are playing a game. they get a circle chain with some beads. initially none of the beads is painted. they take turns to paint the chain. in Each turn one player must paint a unpainted beads. whoever is unable to paint in his turn lose the game. aekdycoin will take the first move.

Now, they thought this game is too simple, and they want to change some rules. in each turn one player must select a certain number of consecutive unpainted beads to paint. the other rules is The same as the original. who will win under the rules? You may assume that both of them are so clever.

Input
First line contains T, the number of test cases. following T line contain 2 integer N, M, indicate the chain has N beads, and each turn one player must paint M consecutive beads. (1 <= N, M <= 1000)

Output
For each case, print "Case # idx:" first where idx is the case number start from 1, and the name of the winner.

Sample Input
2
3 1
4 2

Sample Output
Case #1: aekdycoin
Case #2: abcdxyzk

Author
Jayi

Source
2011 Multi-University Training Contest 14-Host by FZU
 
Turn a ring into a chain
[Cpp]
# Include <iostream>
# Include <cstdlib>
# Include <stdio. h>
# Include <memory. h>
Using namespace std;
Int sg [1010];
Int m;
Int find (int x)
{
If (sg [x]> = 0) return sg [x];
If (x-m <0) return sg [x] = 0;
Bool g [1010] = {0 };
For (int j = x-m; j> = 0; j --)
G [find (j) ^ find (x-m-j)] = 1;
For (int I = 0; I ++)
If (g [I] = 0) return sg [x] = I;
}
Int main ()
{
Int t, n;
Int count = 1;
Scanf ("% d", & t );
While (t --)
{
Scanf ("% d", & n, & m );
Memset (sg,-1, sizeof (sg ));
Printf ("Case # % d:", count ++ );
Int ans = 0;
If (n> = m)
Ans = find (n-m )? ;
If (ans) puts ("aekdycoin ");
Else puts ("abcdxyzk ");
/*
Int ans = 0;
If (n> = m)
Ans = find (n-m );
If (! Ans) puts ("aekdycoin ");
Else puts ("abcdxyzk ");
It seems wrong to write it like this, which makes me very puzzled ~
*/
}
}
/*
Sample Input
2
3 1
4 2
 
 
Sample Output
Case #1: aekdycoin
Case #2: abcdxyzk
 
*/

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.