hdu 1907 尼姆博弈
John
Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3745    Accepted Submission(s): 2116
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.
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
T lines each of them containing information about game winner. Print
“John” if John will win the game or “Brother” in other case.
3
3 5 1
1
1
Brother
#include<stdio.h>
#include<string.h>
#include<math.h>
int a[]; int main(){
int t;
scanf("%d",&t);
int n;
while(t--){
scanf("%d",&n);
bool flag=true;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]!=)
flag=false;
}
int ans=a[];
for(int i=;i<=n;i++)
ans=ans^a[i]; if(flag){
if(n%)
printf("Brother\n");
else
printf("John\n"); }
else{
if(ans)
printf("John\n");
else
printf("Brother\n");
} }
return ;
}
hdu 1907 尼姆博弈的更多相关文章
- hdu 1850(尼姆博弈)
		
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
 - hdu 1907 (尼姆博弈)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...
 - POJ 3480 & HDU 1907 John(尼姆博弈变形)
		
题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...
 - hdu 1849 (尼姆博弈)
		
http://acm.hdu.edu.cn/showproblem.php? pid=1849 简单的尼姆博弈: 代码例如以下: #include <iostream> #include ...
 - HDU.1850 being a good boy in spring festival (博弈论 尼姆博弈)
		
HDU.1850 Being a Good Boy in Spring Festival (博弈论 尼姆博弈) 题意分析 简单的nim 博弈 博弈论快速入门 代码总览 #include <bit ...
 - hdu 1849(Rabbit and Grass) 尼姆博弈
		
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
 - HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)
		
Climbing the Hill Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Su ...
 - HDU 2176 取(m堆)石子游戏  尼姆博弈
		
题目思路: 对于尼姆博弈我们知道:op=a[1]^a[2]--a[n],若op==0先手必败 一个简单的数学公式:若op=a^b 那么:op^b=a: 对于第i堆a[i],op^a[i]的值代表其余各 ...
 - 题解报告:hdu 1850 Being a Good Boy in Spring Festival(尼姆博弈)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1850 Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里 ...
 
随机推荐
- TP框架设置验证码
			
thinkphp框架有专门的的验证码生成的模块 public function shengcheng(){ $n = new \Think\Verify(); $n->entry(); } 下面 ...
 - BeanUtils 工具类
			
一.BeanUtils 概述 BeanUtils 是阿帕奇提供的一套专门用于将一些数据封装到java对象中的工具类; 名词:javaBean:特定格式的java类称为java ...
 - Lesson2
			
#ifdef __cplusplus #include <cstdlib> #else #include <stdlib.h> #endif #include <SDL/ ...
 - 多维的vector定义和初始化
			
vector<vector<int> >vv(3, vector<int>(4));//这里,两个“>”间的空格是不可少的 将构造一个二维向量vv,它含有三个 ...
 - html输入框去除记忆功能
			
自动完成功能,只需把AUTOCOMPLETE设为off即可,如: 整个表单禁止自动完成 HTML code <FORM method=post action="submit.asp&q ...
 - WINDOWS-API:取得系统语言种类-GetOEMCP
			
GetOEMCP VB声明 Declare Function GetOEMCP Lib "kernel32" Alias "GetOEMCP" () As Lo ...
 - Gradle配置最佳实践
			
https://blog.csdn.net/devilnov/article/details/53321164 本文会不定期更新,推荐watch下项目.如果喜欢请star,如果觉得有纰漏请提交issu ...
 - Vue的安装并在WebStorm中运行
			
一.Vue的安装需要两个支持分别为:nodejs.npm Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境. Node.js 使用了一个事件驱动.非阻塞式 I/O ...
 - 项目中多条数据保存的json实例
			
//js代码function checkCode(num){ var typeid = $("#typeid").val(); if(typeid == "") ...
 - C语言特点_01
			
C语言特点: 1.C语言的32个关键字 auto 局部变量(自动储存) break 无条件退出程序最内层循环 case switch语句中选择项 char 单字节整型数据 const 定义不可更改的常 ...