HDU-2509-Be the Winner【nimm】
来源:互联网 发布:韦德2016季后赛数据 编辑:程序博客网 时间:2024/06/05 22:54
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2509
Be the Winner
Problem Description
Let's consider m apples divided into n groups. Each group contains no more than 100 apples, arranged in a line. You can take any number of consecutive apples at one time.
For example "@@@" can be turned into "@@" or "@" or "@ @"(two piles). two people get apples one after another and the one who takes the last is
the loser. Fra wants to know in which situations he can win by playing strategies (that is, no matter what action the rival takes, fra will win).
For example "@@@" can be turned into "@@" or "@" or "@ @"(two piles). two people get apples one after another and the one who takes the last is
the loser. Fra wants to know in which situations he can win by playing strategies (that is, no matter what action the rival takes, fra will win).
Input
You will be given several cases. Each test case begins with a single number n (1 <= n <= 100), followed by a line with n numbers, the number of apples in each pile. There is a blank line between cases.
Output
If a winning strategies can be found, print a single line with "Yes", otherwise print "No".
Sample Input
22 213
Sample Output
NoYes
题目 分析: (和hdu-1907一样)
最后取完者为负。
1)如果全是1的时候,特判,奇数则输。
2)否则 nim博弈,求异或值,为0则输。
1)如果全是1的时候,特判,奇数则输。
2)否则 nim博弈,求异或值,为0则输。
#include<iostream>using namespace std;int main(){int n,i,x;while(cin>>n){int ans=0,flag=0;for(i=1;i<=n;i++){cin>>x;ans^=x;if(x!=1)flag=1;}if(flag){if(ans)cout<<"Yes"<<endl;elsecout<<"No"<<endl;}else{if(n%2)cout<<"No"<<endl;elsecout<<"Yes"<<endl;}}return 0;}
阅读全文
0 0
- HDU-2509-Be the Winner【nimm】
- hdu 2509 Be the Winner
- HDU 2509 Be The Winner
- hdu-2509 Be the Winner
- hdu 2509 Be the Winner
- HDU 2509 Be the Winner
- HDU 2509 Be the Winner
- HDU 2509 Be the Winner
- HDU 2509 Be the Winner
- hdu 2509 Be the Winner
- hdu 2509 Be the Winner
- HDU 2509 Be The Winner ( Nim 博弈 )
- hdu 2509 Be the Winner 1907 John
- hdu 2509 Be the Winner(博弈)
- hdu 2509 - Be the Winner(简单博弈)
- [博弈]HDU 2509 Be the Winner
- HDU 2509 -Be the Winner/ZOJ3113
- hdu 2509 Be the Winner(博弈)
- vb.net版机房重构--泛型与Datatable
- 一些小小的时间优化
- 《如何阅读一本书》—— 读后总结
- python matplotlib之 hist直方图
- 温故知新python3--基础知识1
- HDU-2509-Be the Winner【nimm】
- 通过软件程序消除单片机由外界干扰产生的异常复位的影响(基于STM8S105单片机)
- Tensorflow基础
- 如何使用cd命令
- 关于开机时候的一些问题
- CSU 1047 最长上升子序列 (二分水过)
- 不怕进度慢,就怕进度慢
- LeetCode_111
- 15个顶级Java多线程面试题及答案