Uva_10404-Bachet's Game

Source: Internet
Author: User

[Cpp]
/** Game question .. This kind of question is characterized by: it is very easy to think of after thinking of the method, unexpected
* You can't do it .. I first tried to list all the results, and found that the data volume was too large.
* It didn't work. Later I looked at the game and suddenly burst into a flash, thinking that I only wanted to consider the current
* Step, set the total number to 1 ~ When count is used, the first player wins or loses. The equation is:
* If (I-a [I] = 0 |! Num [I-a [I] (I-a [I]> 0) wins first
* It means that the opponent will lose after moving or moving once.
*/
# Include <cstdio>
# Include <cstring>
Using namespace std;
 
# Define MAX 12
# Deprecision MAXC 121
 
Int a [MAX];
Int num [MAXC];
 
 
Void move_stones (int count, int type ){
For (int I = 1; I <= count; I ++ ){
For (int j = 0; j <type; j ++ ){
If (I-a [j]> 0 &&! Num [I-a [j]) {
Num [I] = 1;
Break;
} Else if (I-a [j] = 0 ){
Num [I] = 1;
Break;
}
}
}
If (num [count])
Printf ("Stan wins \ n ");
Else
Printf ("Ollie wins \ n ");
}
 
Int main (int argc, char const * argv [])
{
# Ifndef ONLINE_JUDGE
Freopen ("test. in", "r", stdin );
# Endif
Int count, type;
While (~ Scanf ("% d", & count )){
Memset (num, 0, sizeof (num ));
Scanf ("% d", & type );
For (int I = 0; I <type; I ++)
Scanf ("% d", & a [I]);
Move_stones (count, type );
}
Return 0;
}

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.