题解——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;
    for(int i=1;i<=m;i++){
      scanf("%d",&mid);
      ans^=mid;
    }
    if(ans)
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}

原文地址:https://www.cnblogs.com/dreagonm/p/9570561.html

时间: 2024-10-21 05:48:05

题解——POJ 2234 Matches Game的相关文章

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博弈裸题)

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(取火柴博弈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^

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(博弈论)

http://poj.org/problem?id=2234 博弈论真是博大精深orz 首先我们仔细分析很容易分析出来,当只有一堆的时候,先手必胜:两堆并且相同的时候,先手必败,反之必胜. 根据博弈论的知识(论文 张一飞:<由感性认识到理性认识——透析一类搏弈游戏的解答过程>) 局面可以分解,且结果可以合并. 局面均是先手 当子局面是 胜 和 败,那么局面则为胜 当子局面是 败 和 胜,那么局面则为胜 当子局面是 败 和 败,那么局面则为败 当子局面为 胜 和 胜,那么局面为不确定 而这些性质

[题解]poj Meteor Shower

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16313   Accepted: 4291 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious fo

[题解]poj 3368 Frequent values

Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16537   Accepted: 5981 Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries consisting of indice

[题解]poj.org Problem#3468

Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In

[题解]poj 1274 The Perfect Stall(网络流)

二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络流(做其它的题的时候,神奇地re掉了,于是就写基础题了)的最大流算法,就做做这道题. 每一个牛都可一看成是个源点,每一个牛棚都可以看成是个汇点,但是一个网络应该只有一个汇点和一个源点才对,于是构造一个连接每个牛的超级源点,一个连接每个牛棚的超级汇点,每条边的容量为1,然后最大流Dinic算法(其它最