hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)
Both of players are using optimal game strategy. John starts first always. You will be given information about M&Ms and your task is to determine a winner of such a beautiful game.
Constraints:
1 <= T <= 474,
1 <= N <= 47,
1 <= Ai <= 4747
3
3 5 1
1
1
Brother
#include <iostream> using namespace std; int main()
{
int t,n;
int sum1,sum2,ans;
int a[];
cin>>t;
while(t--)
{
cin>>n;
sum1=;
sum2=;
ans=;
for(int i=;i<n;i++)
{
cin>>a[i];
ans=ans^a[i];
if(a[i]>=)
sum2++;//富裕堆
else
sum1++;//孤单堆
}
if((ans&&sum2)||(!ans&&!sum2))
cout<<"John"<<endl;
if((ans&&sum1%!=&&sum2==)||(!ans&&sum2>=))
cout<<"Brother"<<endl;
}
return ;
}
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).
2 2
1
3
Yes
#include <iostream> using namespace std; int main()
{
int n,ans,sum1,sum2;
int a[];
while(cin>>n)
{
sum1=sum2=ans=;
for(int i=;i<n;i++)
{
cin>>a[i];
ans=ans^a[i];
if(a[i]>=)
sum2++;
else
sum1++;
}
if((ans&&sum2)||(!ans&&!sum2))
cout<<"Yes"<<endl;
if((ans&&sum1%!=&&sum2==)||(!ans&&sum2>=))
cout<<"No"<<endl;
}
return ;
}
hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)的更多相关文章
- POJ 3480 & HDU 1907 John(尼姆博弈变形)
题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Descri ...
- hdu2509Be the Winner(反nim博弈)
Be the Winner Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 1907 John (anti—Nim)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)http://acm.h ...
- HDU 1907 John nim博弈变形
John Problem Description Little John is playing very funny game with his younger brother. There is ...
- HDU 1907 John (Nim博弈)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- hdu 1907 John(anti nim)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- hdu 1907 John (尼姆博弈)
John Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submis ...
- hdu 1907 John
很简单的博弈论问题!!(注意全是1时是特殊情况) 代码如下: #include<stdio.h> #include<iostream> using namespace std; ...
- HDU 1907 John(取火柴博弈2)
传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int ...
随机推荐
- 一个小团队TDD游戏及实践
介绍的这个游戏是自己根据目前带的团队的实际情况来制定的, 在游戏实践过程中,收到了较好的效果,故打算把这个游戏分享出来,一是分享一下实践,而是集思广益,不断完善,更好的利用游戏来锻炼队伍.下面就将游戏 ...
- 手机APP下单支付序列图
今天安装了Visio,学习了下如何使用,画了一下公司现在项目的下单支付序列图,话就不多说了,直接上图,处女作,欢迎指正!
- silverlight中datagrid数据到处excel
首先新建一个DataGrdiExtensions类,代码为: public static class DataGridExtensions { /// <summary> /// 导出dg ...
- Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同
Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同 <Windows Azure Platform 系列文章目录> 如果熟悉Windows Azure平 ...
- Jquery文本框值改变事件(支持火狐、ie)
Jquery值改变事件支持火狐和ie浏览器,并且测试通过,绑定后台代码可以做成autocomplete控件. 具体代码列举如下: $(document).ready(function () { $(& ...
- 基于“泵”的TCP通讯(接上篇)
基于“泵”的TCP通讯(接上篇) 上一篇博客中说了基于“泵”的UDP通讯,附上了一个Demo,模拟飞鸽传书的功能,功能不太完善,主要是为了说明“泵”在编程中的应用.本篇文章我再附上一个关于TCP通讯的 ...
- 什么时候用spring
论公司spring的滥用 这个公司每个项目用不同的一套开发框架,实在忍不住拿一个出来说说事.
- 淘宝ued - 前端智勇大闯关(第三季)答案(更新)
淘宝ued - 前端智勇大闯关(第三季)答案(更新) 下午在微博上看到了淘宝智勇大闯关第三季的信息,感觉挺有意思的,于是就尝试做了下.附上题目地址: http://ued.campus.alibaba ...
- 黑马程序员:Java基础总结----正则表达式
黑马程序员:Java基础总结 正则表达式 ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 正则表达式 import java.util.regex.*; 符合一定规 ...
- 当你在试衣间试衣服,请你务必想起wait()与notify()
在学习多线程的时候,你无法逃避sleep.wait.notify.notifyAll的关键字,我们肯定是对sleep用的最多,即使你写个Demo也要经常用到Thread.sleep(xxx)模拟等待的 ...