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 ...
随机推荐
- C#通过模板导出Word(文字,表格,图片)
C#通过模板导出Word(文字,表格,图片) C#导出Word,Excel的方法有很多,这次因为公司的业务需求,需要导出内容丰富(文字,表格,图片)的报告,以前的方法不好使,所以寻找新的导出方法, ...
- 实践中总结——理解haslayout和BFC
1.HASLAYOUT 首先,haslayout翻译成中文就是:有布局. 所谓布局,指的是一个元素可以对本身和里边的元素进行尺寸计算和定位.这里只是谈IE6/7,据说微软之所以不是对所有元素默认有布局 ...
- Django数据库迁移
如果你用过Django的数据库就会发现一个比较令人纠结的地方:数据库更改. 我们知道添加或者删除一个models.Model 需要在数据库里相应的操作,这需要我们进入数据库命令行手动添加或删除,因为s ...
- 7 MySQL存储过程和函数
目录: 1. 存储过程和函数概述2. 准备工作3. 存储过程操作4. 创建带参存储过程5. 查看存储过程 1. 存储过程和函数概述 MySQL的存储过程(stored procedure)和函数(st ...
- vm_write
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types. ...
- 程序处理数据库中值字段值为null的查询显示
1.如果你做了一个简单的注册界面,需要用户进行注册,但有些项是不必要填的,当用户完成注册时,数据库表中的相应字段的值会写入null,但如何将查询的字段的值null显示出来? 2.首先我们学习一下如何向 ...
- EasyUI实现异步加载tree(整合Struts2)
首先jsp页面有一ul用于展现Tree <ul id="mytree"></ul> 加载Tree <script type="text/ja ...
- 基于 WebSocket 构建跨浏览器的实时应用
Socket.IO – 基于 WebSocket 构建跨浏览器的实时应用 Socket.IO 是一个功能非常强大的框架,能够帮助你构建基于 WebSocket 的跨浏览器的实时应用.支持主流浏览器,多 ...
- thrift之默认传输类TTransportDefaults和虚拟传输类TVirtualTransport
默认传输类TTransportDefaults提供了抽象类TTransport的默认实现,实现了非虚拟的方法(*_virt) read(), readAll(), write(),borrow() a ...
- HDU 4062 Partition
Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...