POJ 2234

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<algorithm>
 4 #define MAXN 100
 5 using namespace std;
 6 //把所有堆的石子数目用二进制数表示出来,当全部这些数按位异或结果为0时当前局面为必败局面,否则为必胜局面;
 7 int a[MAXN];
 8 void op(int & num);
 9 int trans_10_to_2(int num);
10 int main()
11 {
12     //freopen("acm.acm","r",stdin);
13     int num;
14     int i;
15     int tem;
16     int sum;
17     while(cin>>num)
18     {
19         sum = 0;
20         memset(a,0,sizeof(a));
21         for(i = 0; i < num; ++ i)
22         {
23             cin >> tem;
24             trans_10_to_2(tem);
25         }
26         for_each(a,a+MAXN,op);
27         for(i = 0; i < MAXN; ++ i)
28         {
29             if(a[i] == 1)
30             {
31                 cout<<"Yes"<<endl;
32                 break;
33             }
34         }
35         if(i == MAXN)
36             cout<<"No"<<endl;
37     }
38 }
39
40
41 int trans_10_to_2(int num)
42 {
43     int mod;
44     int i;
45     i = 0;
46     while(num)
47     {
48         mod = num%2;
49         num /= 2;
50         a[i ++] += mod;
51     }
52     return i;
53 }
54
55 void op(int & num)
56 {
57     if(num % 2 == 0)
58         num = 0;
59     else
60         num = 1;
61 }
时间: 2024-08-24 04:44:14

POJ 2234的相关文章

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 博弈论水题 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 尼姆博弈

题目大意:尼姆博弈,判断是否先手必胜. 题目思路: 尼姆博弈:有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 \)游戏,即双方可以任取石子的游戏,\( 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

POJ【数论/组合/博弈论】

 POJ[数论/组合/博弈论]题目列表 POJ[数论/组合/博弈论]题目列表 原来的列表比较水,今天换了一个难一些的列表,重新开始做~ 红色的代表已经AC过,蓝色的代表做了但是还没过.这句话貌似在我空间里的每份列表里都有额. 博弈论 POJ 2234 Matches Game POJ 2975 Nim POJ 2505 A multiplication game POJ 1067 取石子游戏 POJ 2484 A Funny Game POJ 2425 A Chess Game POJ 29

Part.4【博弈论】

---恢复内容开始--- 不要问我为什么突然跳到Part.4,我懒得解释. 在蔡大神的论文+讲解和HZW的题库下,自己大概是明白什么是博弈论的皮毛了吧. 先说SG定理吧. 对于游戏中的状态,我们给每个状态定义一个必胜态和必败态.区别在于前者可以通过一次操作到达必败态,但后者无法做到(后者在一次操作后所能到达的状态全部都为必胜态) 接着引进SG函数,每个状态都有一个SG值,这个值由它所能到达的状态的SG值决定.(这里的所能到达的状态指的是经过一次操作能到达的状态,下同) SG值有以下性质: SG值

(转载)--SG函数和SG定理【详解】

在介绍SG函数和SG定理之前我们先介绍介绍必胜点与必败点吧. 必胜点和必败点的概念: P点:必败点,换而言之,就是谁处于此位置,则在双方操作正确的情况下必败. N点:必胜点,处于此情况下,双方操作均正确的情况下必胜. 必胜点和必败点的性质: 1.所有终结点是 必败点 P .(我们以此为基本前提进行推理,换句话说,我们以此为假设) 2.从任何必胜点N 操作,至少有一种方式可以进入必败点 P. 3.无论如何操作,必败点P 都只能进入 必胜点 N. 我们研究必胜点和必败点的目的时间为题进行简化,有助于

SG函数和SG定理【详解】

在介绍SG函数和SG定理之前我们先介绍介绍必胜点与必败点吧. 必胜点和必败点的概念: P点:必败点,换而言之,就是谁处于此位置,则在双方操作正确的情况下必败. N点:必胜点,处于此情况下,双方操作均正确的情况下必胜. 必胜点和必败点的性质: 1.所有终结点是 必败点 P .(我们以此为基本前提进行推理,换句话说,我们以此为假设) 2.从任何必胜点N 操作,至少有一种方式可以进入必败点 P. 3.无论如何操作,必败点P 都只能进入 必胜点 N. 我们研究必胜点和必败点的目的时间为题进行简化,有助于