hdu2176 取(m堆)石子游戏(nim博弈)
来源:互联网 发布:金融行业 数据安全 编辑:程序博客网 时间:2024/06/05 09:07
取(m堆)石子游戏
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2713 Accepted Submission(s): 1617
Problem Description
m堆石子,两人轮流取.只能在1堆中取.取完者胜.先取者负输出No.先取者胜输出Yes,然后输出怎样取子.例如5堆 5,7,8,9,10先取者胜,先取者第1次取时可以从有8个的那一堆取走7个剩下1个,也可以从有9个的中那一堆取走9个剩下0个,也可以从有10个的中那一堆取走7个剩下3个.
Input
输入有多组.每组第1行是m,m<=200000. 后面m个非零正整数.m=0退出.
Output
先取者负输出No.先取者胜输出Yes,然后输出先取者第1次取子的所有方法.如果从有a个石子的堆中取若干个后剩下b个后会胜就输出a b.参看Sample Output.
Sample Input
245 4533 6 955 7 8 9 100
Sample Output
NoYes9 5Yes8 19 010 3
Author
Zhousc
Source
ECJTU 2008 Summer Contest
题意:中文题.....不说了....
分析:这不和hdu1850差不多嘛;稍微改一下不就行了
#include <iostream>#include <cstdio>#include <cstring>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <cmath>#include <algorithm>using namespace std;const double eps = 1e-6;const double pi = acos(-1.0);const int INF = 1e9;const int MOD = 1e9+7;#define ll long long#define CL(a,b) memset(a,b,sizeof(a))#define lson (i<<1)#define rson ((i<<1)|1)#define N 50010int gcd(int a,int b){ return b?gcd(b,a%b):a;}int n,a[200000+10];int main(){ while(scanf("%d",&n),n) { int sum=0,ans=0; for(int i=0; i<n; i++) { scanf("%d",&a[i]); sum ^= a[i]; } if(sum==0) cout<<"No"<<endl; else { cout<<"Yes"<<endl; for(int i=0; i<n; i++) { if((sum^a[i]) <= a[i]) cout<<a[i]<<" "<<(sum^a[i])<<endl; } } } return 0;}
0 0
- hdu2176 取(m堆)石子游戏(nim博弈)
- hdu2176 取(m堆)石子游戏 nim博弈
- nim博弈 hdu2176 取(m堆)石子游戏
- hdu2176取(m堆)石子游戏 ——Nim 博弈
- HDU2176:取(m堆)石子游戏(Nim)
- hdu 2176 取(m堆)石子游戏(Nim博弈)
- HDU 2176 取(m堆)石子游戏(Nim博弈)
- HDU2176 取(m堆)石子游戏
- hdu2176 取(m堆)石子游戏
- HDU2176 取(m堆)石子游戏
- hdu2176 取(m堆)石子游戏
- hdu2176 取(m堆)石子游戏
- hdu2176取(m堆)石子游戏
- HDU2176 取(m堆)石子游戏
- HDU2176取(m堆)石子游戏
- hdu2176取(m堆)石子游戏 组合游戏初步——NIM
- 博弈论基础 Nim博弈 取(m堆)石子游戏 HDU
- hdu2176取(m堆)石子游戏 nim hdu1848Fibonacci again and again sg
- 【BZOJ3831】Little Bird,单调队列优化DP
- map的嵌套使用
- Markdown简明语法
- uva12716 GCD等于XOR 筛法枚举
- QRgb 学习
- hdu2176 取(m堆)石子游戏(nim博弈)
- LintCode:背包问题 II
- 解决“Cannot merge new index 67208 into a non-jumbo instruction”的问题
- Java NIO原理图文分析及代码实现
- I/O流
- 科室软件开发流程规范
- poj2376Cleaning Shifts_贪心
- Android面试整理之UI部分——实现View的弹性滑动的三种方式(一)
- 基于GPUImage的实时美颜滤镜