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 ...
随机推荐
- spring实现模板文件下载
前台 <form id="batchModel0" method="post" action="/common/download-file&qu ...
- HashMap和List遍历方法总结及如何遍历删除元素
https://blog.csdn.net/demohui/article/details/77748809
- 后缀数组 (Suffix Array) 学习笔记
\(\\\) 定义 介绍一些写法和数组的含义,首先要知道 字典序 . \(len\):字符串长度 \(s\):字符串数组,我们的字符串存储在 \(s[0]...s[len-1]\) 中. \(suff ...
- Spring---AOP注解开发&jdbc模板&Spring事务管理
一.AOP注解开发 此处需要回忆一遍AOP的概念.简单的来说,AOP就是利用动态代理技术,做到不触动源代码但却扩展了功能.那么就需要一个被扩展的对象和一个“新的功能”,例如说给某类的saveUser方 ...
- [Android]如何实现无限滚动的ListViw/GridView(翻译)
ListView和GridView已经成为原生的Android应用实现中两个最流行的设计模式.目前,这些模式被大量的开发者使用,主要是因为他们是简单而直接的实现,同时他们提供了一个良好,整洁的用户体验 ...
- Matlab plotyy画双纵坐标图实例
Matlab plotyy画双纵坐标图实例 x = 0:0.01:20;y1 = 200*exp(-0.05*x).*sin(x);y2 = 0.8*exp(-0.5*x).*sin(10*x);[A ...
- dom监听事件class
layui.use(['layer', 'form'], function(){ var layer = layui.layer ,form = layui.form; var $ = layui.j ...
- JAVA编程不得不看的几本经典书籍
为了帮助对java编程感兴趣的同学更好.更快的提高编程技术,武汉北大青鸟光谷校区专业老师在此推荐几本学习编程非常有用的书籍,以供大家参考. 入门类 1.<java从入门到精通>(第3版) ...
- eclipse 的开发环境配置
一.基础环境设置 1.jdk下载配置 2.JRE下载配置 3.Eclipse下载 4.Eclipde 与JRE配置,见图 二.PHP环境设置 1.apache + PHP 配置. 详见随笔文章:Ecl ...
- python 获取路径
获取目录路径和文件路径 import osfor root, dirs, files in os.walk(".", topdown=False): # ‘.’为获取脚本所在路径下 ...