简单NIm
来源:互联网 发布:怎样在淘宝上做兼职 编辑:程序博客网 时间:2024/06/08 05:06
题目地址:http://115.231.222.240:8081/JudgeOnline/
Problem F: qwb has a lot of Coins
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 661 Solved: 199
[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?
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.
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 311
Sample Output
0
题意:给出几堆数,然后要求先取者为胜的情况。
思路:nim表示的是所有的数异或为1那么先取者胜,否则先取者败。
然后就是选取某一堆的时候,其他的数异或起来比这个数小的话,那么就能把这个数取成与其他数异或起来一样的值,使得所有的数的亦或值变成0,使得对手变成必败态。
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespace std;const int maxn = 1000 + 10;#define INF 0x7fffffff#define clr(x,y) memset(x,y,sizeof(x))typedef long long ll;#define eps 10e-10const ll Mod = 1000000007;bool is_[maxn];int prime[maxn];ll pow_mod(ll x,ll n,ll mod_val){ ll ans = 1; ll t = x % mod_val; while(n) { if(n & 1) { ans = ans * t % mod_val; } n >>= 1; t = t * t % mod_val; } return ans;}int a[maxn];int sum1[maxn],sum2[maxn];int main(){ int n; while( ~ scanf("%d",&n)) { for(int i = 1; i <= n; i ++) scanf("%d",&a[i]); sum1[0] = sum2[n + 1] = 0; for(int i = 1; i <= n; i ++) sum1[i] = sum1[i - 1] ^ a[i]; for(int i = n; i >= 1; i --) sum2[i] = sum2[i + 1] ^ a[i]; int ans = 0; for(int i = 1; i <= n; i ++) { int t = sum1[i - 1] ^ sum2[i + 1]; if(a[i] > t) ans ++; } printf("%d\n",ans); } return 0;} /************************************************************** Problem: 1485 User: ZJC2017Final110 Language: C++ Result: Accepted Time:52 ms Memory:1728 kb****************************************************************/
阅读全文
0 0
- 简单NIm
- nim
- Nim
- Nim
- Nim
- poj 3480 John 简单的nim博弈
- (简单) 博弈 HOJ 2128 S-Nim
- 简单博弈树算法(nim游戏)
- Codeforces 15C Industrial Nim 简单博弈
- leetcode -- Nim Game -- 简单要看
- POJ 2975 Nim题解---简单的博弈论
- HDU 4994 Revenge of Nim(简单博弈)
- HDU 2176 取(m堆)石子游戏 简单Nim游戏
- 用nim写一个简单的windows程序
- Acdream 1416 Crazy Nim(简单博弈找规律)
- HDU1536 S-nim 尼姆博弈简单题
- 51nod 1069 nim游戏(简单博弈)
- Nim的博弈详解(简单易懂)(一)
- QImage
- Android
- 发送有序广播
- 详解 JVM 工作原理和流程
- JAVA高级工程师课程笔记整理——(十)Servlet
- 简单NIm
- 双管道与cmd.exe进程间通信演示
- android App异常报错捕获后使用javamail登录QQ邮箱发邮件的功能遇到的问题
- Hibernate hql语句 find_in_set 用法
- hadoop相关ERROR
- (编程风格)c++编程命名规范
- jsch 【stream的理解】
- elasticsearch5.3.0安装head插件
- 22.spring_使用xml配置事务