2017年第0届浙江工业大学之江学院程序设计竞赛决赛—F

本文探讨了一个关于博弈论的游戏问题,具体为两个玩家轮流从若干堆硬币中取走一部分,目标是移除最后一枚硬币以赢得比赛。文章提供了一段C++代码示例,用于计算首位玩家确保获胜的不同策略数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem F: qwb has a lot of Coins

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 781   Solved: 264
[ Submit][ Status][ Web Board]

Description

qwb has a lot of coins. One day, he decides to play a game with his friend using these coins. He first puts some of his coins into M piles, each of which is composed of Ni (1<=i<=M) coins. Then, the two players play the coin game in turns. Every step, one can remove one or more coins from only one pile. The winner is the one who removes the last coin.
Then comes the question: How many different ways the first player can do that will ensure him win the game? 

Input

Input contains multiple test cases till the end of file. Each test case starts with a number M (1 <= M<= 1000) meaning the number of piles. The next line contains M integers Ni (1 <= Ni <= 1e9, 1 <= i<= M) indicating the number of coins in pile i.

Output

For each case, put the method count in one line.
If the first player can win the game, the method count is the number of different ways that he can do to ensure him win the game, otherwise zero.

Sample Input

3
1 2 3
1
1

Sample Output

0
1
想法:
尼姆博弈
    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main()
    {
       int a[102],m,i,sum,s,count;
       while(scanf("%d",&m)!=EOF&&m)
       {
           sum=count=0;
          for(i=0;i<m;i++)
          {
             scanf("%d",&a[i]);
             sum=sum^a[i];
          }
          for(i=0;i<m;i++)
          {
             s=sum^a[i];
             if(s<a[i])
                 count++;
          }
          printf("%d\n",count);
       }
       return 0;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值