zoukankan      html  css  js  c++  java
  • BZOJ1022 [SHOI2008]小约翰的游戏John 【博弈论】

    1022: [SHOI2008]小约翰的游戏John

    Time Limit: 1 Sec  Memory Limit: 162 MB
    Submit: 3014  Solved: 1914
    [Submit][Status][Discuss]

    Description

      小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取
    的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不取,我们规定取到最后一
    粒石子的人算输。小约翰相当固执,他坚持认为先取的人有很大的优势,所以他总是先取石子,而他的哥哥就聪明
    多了,他从来没有在游戏中犯过错误。小约翰一怒之前请你来做他的参谋。自然,你应该先写一个程序,预测一下
    谁将获得游戏的胜利。

    Input

      本题的输入由多组数据组成第一行包括一个整数T,表示输入总共有T组数据(T≤500)。每组数据的第一行包
    括一个整数N(N≤50),表示共有N堆石子,接下来有N个不超过5000的整数,分别表示每堆石子的数目。

    Output

      每组数据的输出占一行,每行输出一个单词。如果约翰能赢得比赛,则输出“John”,否则输出“Brother”
    ,请注意单词的大小写。

    Sample Input

    2
    3
    3 5 1
    1
    1

    Sample Output

    John
    Brother

    见论文:

    SG

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define LL long long int
    #define REP(i,n) for (int i = 1; i <= (n); i++)
    #define fo(i,x,y) for (int i = (x); i <= (y); i++)
    #define Redge(u) for (int k = head[u]; k != -1; k = edge[k].next)
    using namespace std;
    const int maxn = 100005,maxm = 100005,INF = 1000000000;
    inline int read(){
    	int out = 0,flag = 1;char c = getchar();
    	while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
    	while (c >= 48 && c <= 57) {out = out * 10 + c - 48; c = getchar();}
    	return out * flag;
    }
    int main()
    {
    	int T = read(),N,flag,x,n;
    	while (T--){
    		N = read(); flag = 1; n = 0;
    		REP(i,N){
    			x = read();
    			if (x != 1) flag = 0;
    			n ^= x;
    		}
    		if (flag && (N & 1)) puts("Brother");
    		else if (flag) puts("John");
    		else if (n) puts("John");
    		else puts("Brother");
    	}
    	return 0;
    }
    


  • 相关阅读:
    感光板制作问答
    游戏外挂技术分析(转)
    div 显示和隐藏
    c# 构造sql语句
    Iframe自动适应高度
    .net web图表类
    通讯录从Database导出vCard格式
    winform通过HttpWebRequest(post方式)上传文件和传递参数
    c# CSV读入DataSet
    模拟器显示屏上方的信号和电池图标不显示设置
  • 原文地址:https://www.cnblogs.com/Mychael/p/8282803.html
Copyright © 2011-2022 走看看