zoj3591 Nim(Nim博弈)
题目意思是说有n堆石子,Alice只能从中选出连续的几堆来玩Nim博弈,现在问Alice想要获胜有多少种方法(即有多少种选择方式)。
方法是这样的,由于Nim博弈必胜的条件是所有数的抑或值不为0,证明见 点击 ,所以答案就转化为原序列有多少个区间的亦或值为0,用n*(n+1) / 2 减去这个值就可以了。
而求有多少个区间的亦或值为0,实际上就是求对于亦或值的前缀nim[i],满足nim[i] == nim[j] 的对数,这时只要对nim数组排序就可以算了
详见代码:
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf (-((LL)1<<40))
#define lson k<<1, L, mid
#define rson k<<1|1, mid+1, R
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define rep(i, a, b) for(int i = a; i <= b; i ++) template<class T> T CMP_MIN(T a, T b) { return a < b; }
template<class T> T CMP_MAX(T a, T b) { return a > b; }
template<class T> T MAX(T a, T b) { return a > b ? a : b; }
template<class T> T MIN(T a, T b) { return a < b ? a : b; }
template<class T> T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
template<class T> T LCM(T a, T b) { return a / GCD(a,b) * b; } //typedef __int64 LL;
typedef long long LL;
const int MAXN = ;
const int MAXM = ;
const double eps = 1e-;
//LL MOD = 987654321; int n, a[MAXN], x, s, w, T; int main()
{
while(~scanf("%d", &T)) while(T--) {
cin >> n >> s >> w;
LL ans = (LL)n * (n + ) / ;
int g = s;
rep (i, , n) {
x = g;
if( x == ) { x = g = w; }
if( g% == ) { g = (g/); }
else { g = (g/) ^ w; }
a[i] = a[i - ] ^ x;
if(a[i] == ) ans --;
}
sort(a + , a + n + );
int num = ;
rep (i, , n) {
if(a[i] == a[i - ]) {
ans -= num;
num++;
}
else num = ;
}
cout << ans << endl;
}
return ;
}
zoj3591 Nim(Nim博弈)的更多相关文章
- (转)巴氏(bash)威佐夫(Wythoff)尼姆(Nim)博弈之模板
感谢:巴氏(bash)威佐夫(Wythoff)尼姆(Nim)博弈之模板 转自:http://colorfulshark.cn/wordpress/巴氏(bash)威佐夫(wythoff)尼姆(nim) ...
- HDU 5795 A Simple Nim (博弈 打表找规律)
A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...
- poj 2975 Nim(博弈)
Nim Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5232 Accepted: 2444 Description N ...
- Poj1704:staircase nim【博弈】
题目大意:有一个无限长的一维的棋盘,棋盘上N个格子放置着棋子.两个人轮流操作,每次操作能选择其中一个棋子向左移动,但不能越过其它棋子或者两枚棋子放在同一格中,最后不能操作的人算输,问先手是否必胜? 思 ...
- poj2975 Nim(经典博弈)
Nim Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5866 Accepted: 2777 Description N ...
- Nim游戏博弈(收集完全版)
Nim游戏证明参见: 刘汝佳训练指南P135-写的很酷! 知乎上SimonS关于Nim博弈的回答! Nim游戏的概述: 还记得这个游戏吗? 给出n列珍珠,两人轮流取珍珠,每次在某一列中取至少1颗珍珠, ...
- HDU 5795:A Simple Nim(博弈)
http://acm.hdu.edu.cn/showproblem.php?pid=5795 A Simple Nim Problem Description Two players take t ...
- (转载)Nim游戏博弈(收集完全版)
Nim游戏的概述: 还记得这个游戏吗?给出n列珍珠,两人轮流取珍珠,每次在某一列中取至少1颗珍珠,但不能在两列中取.最后拿光珍珠的人输.后来,在一份资料上看到,这种游戏称为“拈(Nim)”.据说,它源 ...
- Nim游戏博弈
Nim游戏的概述: 还记得这个游戏吗? 给出n列珍珠,两人轮流取珍珠,每次在某一列中取至少1颗珍珠,但不能在两列中取.最后拿光珍珠的人输. 后来,在一份资料上看到,这种游戏称为"拈(Nim) ...
随机推荐
- OCJP考试介绍
OCJP考试介绍 考试名称:SCJP / OCJP / 1Z0-851 考试时间:150分钟 考题题目:60道题 通过条件:大于等于61%的题目正确 考点查询:http://www.pearsonvu ...
- css3 切换贞动画的效果,仿gif效果
/*---第一组动画---*/ .cartonGif_1{ position: absolute; display: block; background:url("img/haihangzh ...
- cakephp之查询
find public find( string $type 'first' , array $query array() ) Queries the datasource and returns a ...
- Java 动态太极图 DynamicTaiChi (整理)
package demo; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import jav ...
- 移动金融APP分析
最近研究了移动互联网金融APP的情况,分享给大家. 这是官方关于互联网金融的范围,包括支付.借贷.众筹.基金.保险和信托. 典型的APP 绑卡的流程普遍采用的四要素鉴权:姓名,身份证,卡号以及银行预留 ...
- codeforce Codeforces Round #201 (Div. 2)
cf 上的一道好题: 首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是 所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #incl ...
- mysql 在大型应用中的架构演变
文正整理自:http://www.csdn.net/article/2014-06-10/2820160 可扩展性 架构的可扩展性往往和并发是息息相关,没有并发的增长,也就没有必要做高可扩展性的架构, ...
- http tcp联系区别
术语TCP/IP代表传输控制协议/网际协议,指的是一系列协议.“IP”代表网际协议,TCP和UDP使用该协议从一个网络传送数据包到另一个网络.把IP想像成一种高速公路,它允许其它协议在上面行驶并找到到 ...
- android4.0以上部分手机绘图时会出现重影
canvas外层的div需要设定属性style="overflow:visible;-webkit-transform: translateZ(0);
- git/github初级运用自如(zz)
----//git/github环境配置 一 . github上创建立一个项目 用户登录后系统,在github首页,点击页面右下角“New Repository” 填写项目信息: project n ...