Acm hdu 1851 a simple game (game)

Source: Internet
Author: User
A simple gametime limit: 1000/1000 ms (Java/other) memory limit: 32768/65535 K (Java/other) total submission (s): 2 accepted submission (s ): 2 problem descriptionagrael likes play a simple game with his friend animal during the classes. in this game there are n piles of stones numbered from 1 to n, the 1st pile has M1 stones, the 2nd pile has m2 stones ,... and the n-th pile contain Mn stones. agrael and animal take turns to move and in each move each of the players can take at most L1 stones from the 1st pile or take at most L2 stones from the 2nd pile or... or take ln stones from the n-th pile. the player who takes the last stone wins.

After Agrael and animal have played the game for months, the teacher finally got angry and decided to punish them. but when he knows the rule of the game, he is so interested in this game that he asks Agrael to play the game with him and if Agrael wins, he won't be punished, can Agrael win the game if the teacher and Agrael both take the best move in their turn?

The teacher always moves first (-_-), and in each turn a player must takes at least 1 stones and they can't take stones from more than one piles.

Inputthe first line contains the number of test cases. each test cases begin with the number n (n ≤ 10), represent there are n piles. then there are n lines follows, the I-th line contains two numbers Mi and Li (20 ≥mi> 0, 20 ≥li> 0 ).

Outputyour program output one line per case, if Agrael can win the game print "yes", else print "no ".

Sample input2
1
5 4
2
1 1
2 2

Sample outputyes
No

Authoragreal @ tju

Sourcehdu 2007 programming contest-Final

Question: N stones, M1, M2,... ·, Mn stones, respectively. Each pile can have a maximum of L1, L2, · ln Stone: two people can only take each stone from a pile at a time, and the person who takes the last stone wins. If the selected person wins, yes is output; otherwise, no is output,

The number in the first row indicates the number of groups of data. The first row of each group of test data is an integer N, indicating that there are n rows, and then n rows are two integers Mi, Li. indicates that the I-th Heap has Mi stones, and a maximum of Li stones can be removed at a time.

Code:

 # Include <  Stdio. h  >  
Int Main ()
{
Int T;
Int I, N;
Int ANS, M, L;
Scanf (
" % D " , & T );
While (T -- )
{
Scanf (
" % D " , & N );
Ans
= 0 ;
For (I = 1 ; I <= N; I ++ )
{
Scanf (
" % D " , & M, & L );
Ans
= Ans ^ (M % (L + 1 ));
}
If (ANS = 0 ) Printf ( " Yes \ n " ); // The winner
Else Printf ( " No \ n " ); // Win first
}
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.