hdu 1851(A Simple Game)(sg博弈)

A Simple Game

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)
Total Submission(s): 1487    Accepted Submission(s): 939

Problem Description

Agrael 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 L1stones 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.

Input

The 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).

Output

Your program output one line per case, if Agrael can win the game print "Yes", else print "No".

Sample Input

2
1
5 4
2
1 1
2 2

Sample Output

Yes
No

Author

[email protected]

Source

HDU 2007 Programming Contest - Final

Recommend

lcy   |   We have carefully selected several similar problems for you:  1852 1854 1858 1730 1857

简单的SG函数题,结果为每个子游戏的sg值的异或,每个子游戏都是简单的巴什博弈

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int t,n,m,l;
 5     scanf("%d",&t);
 6     while(t--)
 7     {
 8         scanf("%d",&n);
 9         int sg=0;
10         for(int i=0;i<n;i++){
11             scanf("%d%d",&m,&l);
12             sg ^= m%(l+1);
13         }
14         if(sg)
15             puts("No");
16         else
17             puts("Yes");
18     }
19     return 0;
20 }

时间: 2024-11-05 20:30:56

hdu 1851(A Simple Game)(sg博弈)的相关文章

hdu 5795 A Simple Nim (sg 博弈)

官方题解: A Simple Nim sg[0]=0 当x=8k+7时sg[x]=8k+8, 当x=8k+8时sg[x]=8k+7, 其余时候sg[x]=x:(k>=0) 打表找规律可得,数学归纳法可证. 具体的打表放在了代码里面 ,详见init函数 /*by*/ #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace s

HDU - 1851 - A Simple Game

先上题目: A Simple Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)Total Submission(s): 1104    Accepted Submission(s): 686 Problem Description Agrael likes play a simple game with his friend Animal during the clas

hdu 1851 尼姆+巴什博弈

先在每堆中进行巴什博弈,然后尼姆 1 #include<stdio.h> 2 int main() 3 { 4 int T; 5 int i,n; 6 int ans,m,l; 7 scanf("%d",&T); 8 while(T--) 9 { 10 scanf("%d",&n); 11 ans=0; 12 for(i=1;i<=n;i++) 13 { 14 scanf("%d%d",&m,&l

HDU 1851 (N个BASH博弈子游戏)

题意:n堆石子,分别有M1,M2,·······,Mn个石子,各堆分别最多取L1,L2,·····Ln个石头,两个人分别取,一次只能从一堆中取,取走最后一个石子的人获胜.后选的人获胜输出Yes,否则输出No, 第一行一个数字表示数据有多少组,每组测试数据第一行是一个整数n,表示有n行,然后n行分别是两个整数Mi,Li. 表示第i堆有Mi个石子,一次最多取Li个石子. Sample Input2 // T1 // n5 4 // m l21 12 2 Sample OutputYesNo 1 #

HDU 3537 Daizhenyang&#39;s Coin(博弈-sg)

Daizhenyang's Coin Problem Description We know that Daizhenyang is chasing a girlfriend. As we all know, whenever you chase a beautiful girl, there'll always be an opponent, or a rival. In order to take one step ahead in this chasing process, Daizhen

HDU 1517 A Multiplication Game (博弈-求sg)

A Multiplication Game Problem Description Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and

HDU 1848(sg博弈) Fibonacci again and again

Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6253    Accepted Submission(s): 2603 Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的: F(1)=1; F(2)

?HDU 5795 A Simple Nim(简单Nim)

HDU 5795 A Simple Nim(简单Nim) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem Description - 题目描述 Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On e

hdu 4974 A simple water problem(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4974 Problem Description Dragon is watching competitions on TV. Every competition is held between two competitors, and surely Dragon's favorite. After each competition he will give a score of either 0 or

hdu 4975 A simple Gaussian elimination problem.(网络流,判断矩阵是否存在)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 Problem Description Dragon is studying math. One day, he drew a table with several rows and columns, randomly wrote numbers on each elements of the table. Then he counted the sum of each row and col