***qwb has a lot of Coins nim博弈
2017-06-04 23:02
267 查看
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
31 2 3
1
1
Sample Output
01
Hint
题意
先手赢(捡完coin)输出赢得方案数后手赢 输出0
题解:
nim博弈方案数 当前堆异或总异或x 即除去这个堆的博弈结果
AC代码
#include <cstdio> int main(){ int n; int ar[1005]; while (~scanf("%d",&n)){ int x = 0; int ans = 0; for (int i = 0; i < n; ++i){ scanf("%d",&ar[i]); x^=ar[i]; }if (x!=0){ for (int i = 0; i < n; ++i){ int y = x^ar[i]; if (ar[i] >= y) ans++; } } printf("%d\n",ans); } return 0; }
*方案数求法???
相关文章推荐
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛 F: qwb has a lot of Coins [nim]【博弈】
- 简单博弈 之江学院 F qwb has a lot of Coins
- ZJCoj qwb has a lot of Coins ( 博弈
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛 Problem F: qwb has a lot of Coins (博弈论)
- 之江学院第0届校赛决赛 F-qwb has a lot of Coins
- Codeforces Round #260 (Div. 1) B. A Lot of Games Trie + 博弈
- Return of the Nim----Nim博弈+威佐夫博弈 山东省第八届省赛A题
- CF455B - A Lot of Games(Trie树+博弈)
- 山东省第八届省赛 Return of the Nim(博弈)
- CF 455B(A Lot of Games-树上博弈)
- 省SD2017 A Return of the Nim【威佐夫博弈+NIM】
- ZOJ 3964 Yet Another Game of Stones(Nim博弈 待整理)
- hdu 4994 Revenge of Nim 博弈
- HDU 5088 Revenge of Nim II(尼姆博弈,高斯消元)
- 2017 省赛 山东 A Return of the Nim 【博弈】【Nim+Wythoff】
- A Lot of Games(Trie树 + 博弈)
- Exception has been thrown by the target of an invocation
- variable 'std:ofstream' has initializer but incomplete type
- 解决问题The content of the adapter has changed but ListView did not receive a notification.
- The content of the adapter has changed but ListView did not receive a notification