POJ 2234 Matches Game(取火柴博弈1)

传送门

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int a,res=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a);
            res^=a;
        }
        if(!res)//T
            printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}
时间: 2024-08-25 06:26:49

POJ 2234 Matches Game(取火柴博弈1)的相关文章

POJ 2234 Matches Game(Nim博弈裸题)

Description Here is a simple game. In this game, there are several piles of matches and two players. The two player play in turn. In each turn, one can choose a pile and take away arbitrary number of matches from the pile (Of course the number of mat

POJ 2234 Matches Game 尼姆博弈

题目大意:尼姆博弈,判断是否先手必胜. 题目思路: 尼姆博弈:有n堆各a[]个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取一个,多者不限,最后取光者得胜. 获胜规则:ans=(a[1]^a[2] --^a[n]),若ans==0则后手必胜,否则先手必胜. #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<stdio.h>

POJ 2234 Matches Game 博弈论水题 Nim模型

Description Here is a simple game. In this game, there are several piles of matches and two players. The two player play in turn. In each turn, one can choose a pile and take away arbitrary number of matches from the pile (Of course the number of mat

题解——POJ 2234 Matches Game

这道题也是一个博弈论 根据一个性质 对于\( Nim \)游戏,即双方可以任取石子的游戏,\( SG(x) = x \) 所以直接读入后异或起来输出就好了 代码 #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int m; int main(){ while(scanf("%d",&m)!=EOF){ int ans=0,mid; f

HDU 2509 Be the Winner(取火柴博弈2)

传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int n; while(~scanf("%d",&n)) { int a,res=0; int c=0,g=0; for(int i=0;i<n;i++) { scanf("%d",&a); if(a>=2) c++;

取火柴-博弈论

取火柴 (10分)C时间限制:3000 毫秒 | C内存限制:3000 Kb题目内容: 有n个火柴棍,两个游戏玩家a和b轮流取,规则是第一次取的人最少取1根,最多取n-1根,随后每人最多只能取对方上一次取的数目 的2倍,最少取1根.谁取到最后一根为胜者.试问先取的人是赢还是输. 输入描述n输出描述1表示胜,0表示输输入样例3输出样例0 解析:说白了,就是每个人只能取1或者2.(双方都不想因为自己而让对方的选择余地变大) #include<iostream> using namespace st

【贪心】取火柴游戏

[贪心]取火柴游戏 题目描述 输入k及k个整数n1,n2,…,nk,表示有k堆火柴棒,第i堆火柴棒的根数为ni:接着便是你和计算机取火柴棒的对弈游戏.取的规则如下:每次可以从一堆中取走若干根火柴,也可以一堆全部取走,但不允许跨堆取,也不允许不取. 谁取走最后一根火柴为胜利者. 例如:k=2,n1=n2=2,A代表你,P代表计算机,若决定A先取: A:(2,2)→(1,2)    {从一堆中取一根} P:(1,2)→(1,1)    {从另一堆中取一根} A:(1,1)→(1,0) P:(1,0)

【博弈论】取火柴游戏

取火柴游戏 时间限制: 1 Sec  内存限制: 128 MB 题目描述 输入k及k个整数n1,n2,…,nk,表示有k堆火柴棒,第i堆火柴棒的根数为ni:接着便是你和计算机取火柴棒的对弈游戏.取的规则如下:每次可以从一堆中取走若干根火柴,也可以一堆全部取走,但不允许跨堆取,也不允许不取. 谁取走最后一根火柴为胜利者. 例如:k=2,n1=n2=2,A代表你,P代表计算机,若决定A先取: A:(2,2)→(1,2)    {从一堆中取一根} P:(1,2)→(1,1)    {从另一堆中取一根}

不连续取球(取球博弈)

今盒子里有n个小球,A.B两人轮流从盒中取球,每个人都可以看到另一个人取了多少个,也可以看到盒中还剩下多少个,并且两人都很聪明,不会做出错误的判断. 我们约定: 每个人从盒子中取出的球的数目必须是:1,3,7或者8个. 轮到某一方取球时不能弃权! A先取球,然后双方交替取球,直到取完. 被迫拿到最后一个球的一方为负方(输方) 请编程确定出在双方都不判断失误的情况下,对于特定的初始球数,A是否能赢? 程序运行时,从标准输入获得数据,其格式如下: 先是一个整数n(n<100),表示接下来有n个整数.