Being a Good Boy in Spring Festival 博弈论 Nim博弈
kiki's gameTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/10000 K (Java/Others) Problem Description
Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she just playes the checkerboard game.The size of the chesserboard is n*m.First of all, a coin is placed in the top right corner(1,m). Each time one people can move the coin into the left, the underneath or the left-underneath blank space.The person who can't make a move will lose the game. kiki plays it with ZZ.The game always starts with kiki. If both play perfectly, who will win the game?
Input
Input contains multiple test cases. Each line contains two integer n, m (0<n,m<=2000). The input is terminated when n=0 and m=0.
Output
If kiki wins the game printf "Wonderful!", else "What a pity!".
Sample Input
5 3
5 4 6 6 0 0 Sample Output
What a pity!
Wonderful! Wonderful! Author
月野兔
Source
Recommend
|
已知Nim博弈的必败态条件是:所有集合的异或是0.
这个题目要求有多少种操作,就是有有多少种方式可以由当前状态转移到一个必败态
首先求出异或和,判断当前状态
如果是必胜态,那么尝试着从其中一个集合取数,让这个集合和其他集合的异或和为0.
其他集合的异或和 可用 sum^a[i]来求出 sum^a[i]就等价于a[]中除了a[i]的异或和,因为异或是可逆的操作
然后判断当前的a[i]如果大于sum^a[i],就可以操作这个数字,ans++
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<functional>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL; #define N 100
#define MAXN 20000 + 9
#define INF 1000000009
#define eps 0.00000001
#define sf(a) scanf("%d",&a) int n;
int a[N];
int main()
{
while (sf(n), n)
{
int sum = ;
for (int i = ; i < n; i++)
sf(a[i]), sum ^= a[i];
if (sum == )
cout << << endl;
else
{
int ans = ;
for (int i = ; i < n; i++)
{
if ((sum^a[i]) < a[i])
ans++;
}
cout << ans << endl;
}
}
}
Being a Good Boy in Spring Festival 博弈论 Nim博弈的更多相关文章
- HDU 1850 Being a Good Boy in Spring Festival (Nim博弈)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
- HDU.1850 being a good boy in spring festival (博弈论 尼姆博弈)
HDU.1850 Being a Good Boy in Spring Festival (博弈论 尼姆博弈) 题意分析 简单的nim 博弈 博弈论快速入门 代码总览 #include <bit ...
- hdu 1850 Being a Good Boy in Spring Festival 博弈论
求可行的方案数!! 代码如下: #include<stdio.h> ]; int main(){ int n,m; while(scanf("%d",&n)&a ...
- Being a Good Boy in Spring Festival 尼姆博弈
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Descr ...
- HDU1850 Being a Good Boy in Spring Festival
/* HDU1850 Being a Good Boy in Spring Festival http://acm.hdu.edu.cn/showproblem.php?pid=1850 博弈论 尼姆 ...
- HDU1850 Being a Good Boy in Spring Festival(博弈)
Being a Good Boy in Spring Festival Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I ...
- hdu 1850 Being a Good Boy in Spring Festival(Nimm Game)
题意:Nimm Game 思路:Nimm Game #include<iostream> #include<stdio.h> using namespace std; int ...
- Being a Good Boy in Spring Festival(尼姆博弈)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- Being a Good Boy in Spring Festival(杭电1850)(尼姆博弈)
Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32 ...
随机推荐
- 为OS X开发者准备的15个超棒应用
几乎所有的开发人员在他们日常的开发工作中都有他们自己不可缺少的工具或实用程序集. 这些工具中的每一个都提供了特定的功能,大多数开发者都已经将他们集成到了其工作流程中. 使用这些工具或实用程序不单单只是 ...
- VS2012出现加载失败时的解决办法 win7同样适用
今天更新了WIN8系统补丁,然后就出现了大量的问题,特别是经常用的软件像VS2012 老是加载失败,还说是缺少什么包一类的,弄了好长段时间终于解决了,现在将经验分享下 工具/原料 VS2012+WIN ...
- vue组件、数据解析的实现思想猜想与实践
Vue的全局组件,在注册后,可在全局范围内无限次使用,猜想是利用了闭包"可以保持形参"的特性,使初始化时的作用域得意保存,下面用原生js和部分jquery代码模拟了数据解析和组件渲 ...
- 开发小Tips
Kotlin语言篇: 1.抽象类的定义 abstract class Person(var name : String, var age : Int) : Any() { abstract var a ...
- linux下mysql开启可访问
修改mysql配置连接信息 将bind-address注释 vim /etc/my.cnf 修改mysql用户授权 mysql>GRANT ALL PRIVILEGES ON *.* TO ' ...
- JSP标签 <meta.....>作用总结
<metahttp-equiv="pragma" content="no-cache"> <metahttp-equiv="cach ...
- 慎将MBTI测试用于招聘或就业:4星|《人格魅力修炼指南》
人格魅力修炼指南:成为理想中的自己,就靠它了!(<哈佛商业评论>增刊) <哈佛商业评论>的11篇领导者人格魅力相关的文章.比较专业. 一些重要的信息:慎将MBTI测试用于“招聘 ...
- 常用的HTTP方法有哪些?
GET: 用于请求访问已经被URI(统一资源标识符)识别的资源,可以通过URL传参给服务器POST:用于传输数据给服务器,主要功能与GET方法类似,但一般推荐使用POST方式.PUT: 传输数据,报文 ...
- UML-画类图与交互图的顺序
并行.画完交互图,在画类图.交替进行.
- 为了安全请不要随意在页面中设置validateRequest="false"
为了安全请不要随意在页面中设置validateRequest="false" 分类: ASP.NET2009-04-12 17:24 531人阅读 评论(0) 收藏 举报 asp. ...