bzoj千题计划112:bzoj1022:[shoi2008]小约翰的游戏john

日拱一卒功不唐捐 日拱一卒功不唐捐     2022-10-02     183

关键词:

http://www.lydsy.com/JudgeOnline/problem.php?id=1022

 

http://www.cnblogs.com/TheRoadToTheGold/p/6744825.html

 

#include<cstdio>
#include<iostream>

using namespace std;

void read(int &x)
{
    x=0; char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }
}

int main()
{
    int T;
    read(T);
    int n,x,sum,xo;
    while(T--)
    {
        read(n); xo=sum=0;
        while(n--)
        {
            read(x);
            if(x!=1) sum++;
            xo^=x;
        }
        if(xo && !sum)  puts("Brother"); 
        else if(!xo && sum>=2) puts("Brother");
        else puts("John");
    }
}

 

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

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 3002  Solved: 1906
[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

HINT

 

Source

bzoj千题计划120:bzoj1032[jsoi2007]祖码zuma

http://www.lydsy.com/JudgeOnline/problem.php?id=1032 https://www.luogu.org/discuss/show?postid=8416 #include<cstdio>#include<cstring>#include<iostream>usingnamespacestd;#de 查看详情

bzoj千题计划214:bzoj3589:动态树

http://www.lydsy.com/JudgeOnline/problem.php?id=3589 树链剖分用线段数维护扫描线的方式来写,标记只打不下传 #include<cstdio>#include<iostream>#include<algorithm>#defineN200001usingnamespacestd;intn;in 查看详情

bzoj千题计划119:bzoj1029:[jsoi2007]建筑抢修

http://www.lydsy.com/JudgeOnline/problem.php?id=1029 把任务按截止时间从小到大排序如果当前时间+当前任务耗时<=当前任务截止时间,把这个任务耗时放到大根堆里,ans++否则如果堆顶>当前任务耗时,删除堆顶,把这个任务耗时放... 查看详情

bzoj千题计划219:bzoj1568:[jsoi2008]bluemary开公司

http://www.lydsy.com/JudgeOnline/problem.php?id=1568 写多了就觉着水了。。。 #include<cstdio>#include<iostream>#include<algorithm>usingnamespacestd;#defineN100001doublea[N<<2],b[ 查看详情

bzoj千题计划197:bzoj4247:挂饰

http://www.lydsy.com/JudgeOnline/problem.php?id=4247 先把挂饰按挂钩数量从大到小排序dp[i][j]前i个挂饰,剩下j个挂钩的最大喜悦值分挂和不挂转移 #include<cstdio>#include<cstring>#include<iostream>#include<algorit 查看详情

bzoj千题计划106:bzoj1014[jsoi2008]火星人prefix

 http://www.lydsy.com/JudgeOnline/problem.php?id=1014 两个后缀的最长公共前缀:二分+hash带修改带插入:splay维护#include<cstdio>#include<cstring>#include<iostream>#defineL100001typedefunsignedlongl 查看详情

bzoj千题计划123:bzoj1027:[jsoi2007]合金

http://www.lydsy.com/JudgeOnline/problem.php?id=1027 因为x+y+z=1,所以z=1-x-y第三维可以忽略 将x,y看做平面上的点 简化问题:若只有两种材料,那么可以合成两点线段上的所有的点 推广到多种材料:若用户点在材料点构成的... 查看详情

bzoj千题计划165:bzoj5127:数据校验

http://www.lydsy.com/JudgeOnline/upload/201712/prob12.pdf 区间的任意一个子区间都满足值域连续等价于区间任意一个长为2的子区间都满足值域连续即区间任意相邻的两个数大的减小的<=1线段树维护即可 #include<cstdio>#include<iost... 查看详情

bzoj千题计划144:bzoj1176:[balkan2007]mokia

http://www.lydsy.com/JudgeOnline/problem.php?id=1176 CDQ分治 #include<cstdio>#include<iostream>#include<algorithm>#definelowbit(x)x&-xusingnamespacestd;#defineN160001#def 查看详情

bzoj千题计划177:bzoj1858:[scoi2010]序列操作

http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018自己写的第1题,一遍过^_^元旦快乐 #include<cstdio>#include<iostream>#include<algorithm>usingnamespacestd;#defineN100001structnode{ 查看详情

bzoj千题计划142:bzoj3144:[hnoi2013]切糕

http://www.lydsy.com/JudgeOnline/problem.php?id=3144 如果D=2,两个点,高度为4,建图如下   #include<queue>#include<cstdio>#include<cstring>#include<iostream>#include<alg 查看详情

bzoj千题计划242:bzoj4034:[haoi2015]树上操作

http://www.lydsy.com/JudgeOnline/problem.php?id=4034 dfs序,树链剖分 #include<cstdio>#include<iostream>usingnamespacestd;#defineN100001typedeflonglongLL;intn,a[N];intfront[N],nxt[N< 查看详情

bzoj千题计划139:bzoj2229:[zjoi2011]最小割

http://www.lydsy.com/JudgeOnline/problem.php?id=2229  最小割树介绍:http://blog.csdn.net/jyxjyx27/article/details/42750833http://blog.csdn.net/miaomiao_ymxl/article/details/54931876 #include&l 查看详情

bzoj千题计划199:bzoj1055:[haoi2008]玩具取名

http://www.lydsy.com/JudgeOnline/problem.php?id=1055 区间DPdp[i][j][k]表示区间[i,j]能否合成k #include<cstdio>#include<cstring>usingnamespacestd;boolok[4][4][4];chars[201];booldp[201][201][ 查看详情

bzoj千题计划115:bzoj1024:[scoi2009]生日快乐

http://www.lydsy.com/JudgeOnline/problem.php?id=1024 枚举横着切还是竖着切,一边儿分多少块 #include<cstdio>#include<algorithm>usingnamespacestd;doubleS;doubledfs(doublex,doubley,intn){if(n==1)retur 查看详情

bzoj千题计划171:bzoj2456:mode

http://www.lydsy.com/JudgeOnline/problem.php?id=2456 任意删除序列中两个不同的数,众数仍然是众数不停的删,剩下的最后的数一定是众数 具体实现:记录一个当前数和出现次数如果下一个数和当前数不相等,出现次数-1当出现次数... 查看详情

bzoj千题计划236:bzoj2300:[haoi2011]防线修建

http://www.lydsy.com/JudgeOnline/problem.php?id=2300 维护动态凸包,人懒用的set用叉积判断,不要用斜率#include<set>#include<cmath>#include<cstdio>#include<iostream>usingnamespacestd;#defineN10000 查看详情

bzoj千题计划137:bzoj[cqoi2014]危桥

http://www.lydsy.com/JudgeOnline/problem.php?id=3504 往返n遍,即单向2*n遍危桥流量为2,普通桥流量为inf原图跑一遍最大流交换b1,b2再跑一遍最大流如果两次的结果都等于(an+bn)*2则可以 证明参见http://www.cnblogs.com/chenyushuo/p/5139556.ht... 查看详情