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
Agreal@TJU
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1852 1854 1858 1730 1857 
 
简单的SG函数题,结果为每个子游戏的sg值的异或,每个子游戏都是简单的巴什博弈
 #include<stdio.h>
int main()
{
int t,n,m,l;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int sg=;
for(int i=;i<n;i++){
scanf("%d%d",&m,&l);
sg ^= m%(l+);
}
if(sg)
puts("No");
else
puts("Yes");
}
return ;
}
 

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

  1. HDU 5795 A Simple Nim (博弈 打表找规律)

    A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...

  2. HDU 1851 A Simple Game

    典型的尼姆博弈,在n对石子中,告诉你每堆的数目和每次从该堆最多可以取的数目,求最终谁将其取完. 题解:SG(i)=mi%(li+1),求异或值即可. #include <cstdio> i ...

  3. hdu 1851 尼姆+巴什博弈

    先在每堆中进行巴什博弈,然后尼姆 #include<stdio.h> int main() { int T; int i,n; int ans,m,l; scanf("%d&qu ...

  4. hdu 1851 A Simple Game 博弈论

    简单博弈问题(巴什博弈-Bash Game) 巴什博弈:只有一堆n个物品,两个人轮流从这对物品中取物,规定每次至少取一个,最多取m个,最后取光着得胜. 很容易想到当n%(m+1)!=0时,先取者必胜, ...

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

    题意:n堆石子,分别有M1,M2,·······,Mn个石子,各堆分别最多取L1,L2,·····Ln个石头,两个人分别取,一次只能从一堆中取,取走最后一个石子的人获胜.后选的人获胜输出Yes,否则输 ...

  6. HDU 1848(sg博弈) Fibonacci again and again

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  7. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  8. HDU 5794 - A Simple Chess

    HDU 5794 - A Simple Chess题意: 马(象棋)初始位置在(1,1), 现在要走到(n,m), 问有几种走法 棋盘上有r个障碍物, 该位置不能走, 并规定只能走右下方 数据范围: ...

  9. HDU 4974 A simple water problem(贪心)

    HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...

  10. hdu 4972 A simple dynamic programming problem(高效)

    pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic progra ...

随机推荐

  1. 在同一台机器上启动多个tomcat服务(转)

    转载:https://blog.csdn.net/wangxy799/article/details/53957770 1.案例:配置一台机上配置三个Tomcat 2.方法1:[只用修改第一个以外To ...

  2. 相机imu外参标定

    1. 第一步初始化imu外参(可以从参数文档中读取,也可以计算出),VINS中处理如下: # Extrinsic parameter between IMU and Camera. estimate_ ...

  3. Java并发编程系列一:Future和CompletableFuture解析与使用

    一.Future模式 Java 1.5开始,提供了Callable和Future,通过它们可以在任务执行完毕之后得到任务执行结果. Future接口可以构建异步应用,是多线程开发中常见的设计模式. 当 ...

  4. HBase 数据的多版本特性潜在的意外

    HBase做为KeyValue结构存储,在存储上是依照RowKey的字典序进行排序,对于很多应用而言这可能远远不够,好在HBase的数据可以存储多个版本,并且版本可以排序,其理论上最大的版本数目Int ...

  5. 一次IPC无法创建的问题

    背景说明:         后台子系统都是运行在pc上的linux         系统有多个子系统,有一个子系统负责统一启停其他子系统,这里把这个子系统称为olddriver.         ol ...

  6. 后续博客转移到zhylj.cc

    此博客暂不更新了 zhylj.cc

  7. python+selenium 环境配置

    配置环境: python:3.5 selenium:3.3.0 安装方式:python pip install -u selenium windows: 10 firefox:52 因为firefox ...

  8. 各种对list,string操作函数的总结

    #encoding=utf-8#reverse,用来反转lista=['aa','bb','cc']a.reverse()print a#['cc', 'bb', 'aa']#不能直接print a. ...

  9. jmeter属性设置

    使用${__setProperty(newuserid,1,)}函数对属性进行设置 2.使用${__P(userid)}函数在其他线程组中引用该属性 备注: 1.JMeter属性在测试脚本的任何地方都 ...

  10. 什么是Spark

    什么是Spark Apache Spark是一个开源集群运算框架, 相对于Hadoop的MapReduce会在运行完工作后将中介数据存放到磁盘中,Spark使用了存储器内运算技术,能在数据尚未写入硬盘 ...