• BZOJ1022 [SHOI2008]小约翰的游戏John


    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

    HINT

    Source

     
     
    正解:博弈论
    解题报告:
      博弈论裸题,贾志豪的论文里面已经讲了这个模型,不再赘述。
      只有在  不全为1且SG不为0或者全为1且SG为0 的情况下才会有先手必胜(即会让对方取到最后一个)。
      
     
     1 //It is made by jump~
     2 #include <iostream>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <algorithm>
     8 #include <ctime>
     9 #include <vector>
    10 #include <queue>
    11 #include <map>
    12 #include <set>
    13 using namespace std;
    14 typedef long long LL;
    15 int n,x,SG;
    16 bool flag;
    17 
    18 inline int getint()
    19 {
    20        int w=0,q=0; char c=getchar();
    21        while((c<'0' || c>'9') && c!='-') c=getchar(); if(c=='-') q=1,c=getchar(); 
    22        while (c>='0' && c<='9') w=w*10+c-'0', c=getchar(); return q ? -w : w;
    23 }
    24 
    25 inline void work(){
    26     int T=getint(); 
    27     while(T--) {
    28     n=getint(); flag=false; SG=0; for(int i=1;i<=n;i++) { x=getint(); SG^=x; if(x>1) flag=1; } 
    29     if((flag==false&&SG==0) || (flag==true&&SG>0)) printf("John"); else printf("Brother");
    30     printf("
    ");
    31     }
    32 }
    33 
    34 int main()
    35 {
    36   work();
    37   return 0;
    38 }
  • 相关阅读:
    day23,xml 和面向对象
    day22,ConfigParser,subprocess,xlrd三个模块
    re的总结
    day20,日志和正则表达式
    day19,序列化与反序列化总结,和其它的有些模块
    字符串的内建函数
    字符串和编码
    python解释器分类
    git &github 快速入门
    do export method of oracle all database tables with dmp files.
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/5873271.html
Copyright © 2020-2023  润新知