POJ 3480 & HDU 1907 John(尼姆博弈变形)

时间:2022-08-31 13:40:27

题目链接:

PKU:http://poj.org/problem?

id=3480

HDU:http://acm.hdu.edu.cn/showproblem.php?

pid=1907

Description

Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to eat several M&Ms of the same color. Then his opponent has to make a turn. And so on. Please note that each player
has to eat at least one M&M during his turn. If John (or his brother) will eat the last M&M from the box he will be considered as a looser and he will have to buy a new candy box.

Both of players are using optimal game strategy. John starts first always. You will be given information about M&Ms and your task is to determine a winner of such a beautiful game.

Input

The first line of input will contain a single integer T – the number of test cases. Next T pairs of lines will describe tests in a following format. The first line of each test will contain an integer N –
the amount of different M&M colors in a box. Next line will contain N integers Ai, separated by spaces – amount of M&Ms of i-th color.

Constraints:

1 <= T <= 474,

1 <= N <= 47,

1 <= Ai <= 4747

Output

Output T lines each of them containing information about game winner. Print “John” if John will win the game or “Brother” in other case.

Sample Input

2
3
3 5 1
1
1

Sample Output

John
Brother

Source

PS:

尼姆博弈变形!

代码例如以下:

#include <cstdio>
#define maxn 5017
int main()
{
int t;
int a[maxn];
int n, s, k;
scanf("%d",&t);
while(t--)
{
s = 0, k = 0;
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
if(a[i] > 1)
k++;
s = s^a[i];
}
if(k == 0)//全为1
{
if(n%2 == 0)//偶数堆
printf("John\n");
else
printf("Brother\n");
}
else
{
if(s)
printf("John\n");
else
printf("Brother\n");
}
}
return 0;
}

POJ 3480 &amp; HDU 1907 John(尼姆博弈变形)的更多相关文章

  1. hdu 1907 John &lpar;尼姆博弈&rpar;

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  2. hdu 1907 (尼姆博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...

  3. hdu 1849 (尼姆博弈)

    http://acm.hdu.edu.cn/showproblem.php? pid=1849 简单的尼姆博弈: 代码例如以下: #include <iostream> #include ...

  4. HDU 1907 John (Nim博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  5. John 尼姆博弈

    John Little John is playing very funny game with his younger brother. There is one big box filled wi ...

  6. HDU 1907:John(尼姆博弈变形)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submi ...

  7. HDU - 1907 John 反Nimm博弈

    思路: 注意与Nimm博弈的区别,谁拿完谁输! 先手必胜的条件: 1.  每一个小游戏都只剩一个石子了,且SG = 0. 2. 至少有一堆石子数大于1,且SG不等于0 证明:1. 你和对手都只有一种选 ...

  8. hdu 1907 尼姆博弈

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  9. hdu 4315 Climbing the Hill &amp&semi;&amp&semi; poj 1704 Georgia and Bob阶梯博弈--尼姆博弈

    参考博客 先讲一下Georgia and Bob: 题意: 给你一排球的位置(全部在x轴上操作),你要把他们都移动到0位置,每次至少走一步且不能超过他前面(下标小)的那个球,谁不能操作谁就输了 题解: ...

随机推荐

  1. Compute Resource Consolidation Pattern 计算资源整合模式

    Consolidate multiple tasks or operations into a single computational unit. This pattern can increase ...

  2. 需求:输入一个年份和月份 ,显示当前月日情况 ,星期数要对应准确 &ast; 1&period;1900年1月1号开始 &ast; 2&period;星期 : 直接用总天数对7求余数 31 28 59 &sol; 7 &equals; 5 &ast; 3&period;以&bsol;t来个开

    public class Demo4 { /** * @param args */ public static void main(String[] args) { // TODO Auto-gene ...

  3. Guava集合-BiMap

    在本篇文章中我们将介绍Guava集合中的BiMap这个接口. com.google.common.collect Interface BiMap<K,V> BiMap接口的父接口是Map& ...

  4. ASP&period;NET MVC got 405 error on HTTP DELETE request

    使用Backload的时候在本地调试通过,上传服务器后出现405错误(监控通信时可以发现ajax的返回结果为405) 通过修改webconfig可以解决: <system.webServer&g ...

  5. 【HDOJ】2707 Steganography

    简单字符串,读懂题,很容易AC. #include <stdio.h> #include <string.h> ], line[], des[]; int main() { i ...

  6. 对Conjugate Gradient 优化的简单理解

    对Conjugate Gradient 优化的简单理解) 机器学习&数据挖掘笔记_12(对Conjugate Gradient 优化的简单理解) 数学优化方法在机器学习算法中至关重要,本篇博客 ...

  7. fetch使用的常见问题及解决办法

    首先声明一下,本文不是要讲解fetch的具体用法,不清楚的可以参考MDN fetch教程. 引言 说道fetch就不得不提XMLHttpRequest了,XHR在发送web请求时需要开发者配置相关请求 ...

  8. MFC获取可执行文件(exe)所在文件目录

    可以应用函数GetModuleFileName(),举一个例子: CString strexe; ::GetModuleFileName(NULL,strexe.GetBufferSetLength( ...

  9. jQ 移动端返回顶部代码整理

    //返回顶部 $('#btn-scroll').on('touchend',function(){ var T = $(window).scrollTop(); var t = setInterval ...

  10. svn&plus;http&plus;ad域

    svn本地添加用户太麻烦了,如果公司有一百个开发人员要访问,要创建账号密码太麻烦了:所以让他们用AD域账号去登录就很方便,但是权限的管控还是在svn的本地添加(这个暂时还没办法很好的解决) 一.安装依 ...