HDU 1907 —— John

    xiaoxiao2021-12-14  16

    原题:http://acm.hdu.edu.cn/showproblem.php?pid=1907

    题意:取法和Nim游戏一样,但是最后拿完的那个人是loser;

    思路:需要考虑特殊情况 —— 最开始每堆的个数都为1,这个时候对堆数进行奇偶判断;

    #include<iostream> using namespace std; const int maxn = 50; int cas, n; int a[maxn]; int main(){ cin>>cas; while(cas--){ cin>>n; int x = 0; int cnt = 0; for(int i = 0;i<n;i++){ cin>>a[i]; if(a[i] == 1) cnt++; x = x^a[i]; } if(cnt == n){ if(n%2 == 0) cout<<"John"<<endl; else cout<<"Brother"<<endl; continue; } if(x == 0) cout<<"Brother"<<endl; else cout<<"John"<<endl; } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-964740.html

    最新回复(0)