poj2975--Nim
题意:对于一个给定的取石子游戏,有多少种先手策略获胜?
Ans:若无法获胜,则输出0。
若能获胜我们只要找到一堆石子,使得我们能取它的一部分让总和的异或和变为0。我们先将整个游戏的值异或起来为s
则a[i]^s就是除了第i堆以外的其他所有堆的异或和,如果这个异或和小于a[i],说明我们可以通过取这堆石子让异或和等于0。
(为什么不能取等号?,因为一堆石子我们如果取,不能取0个石子)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
int n,ans,x,a[];
int main(){
while (~scanf("%d",&n)){
if (n==) break;
int s=;
for (int i=;i<=n;i++){
scanf("%d",&a[i]);
s^=a[i];
}
ans=;
for (int i=;i<=n;i++)
if ((s^a[i])<a[i]) ans++;
printf("%d\n",ans);
}
}
poj2975--Nim的更多相关文章
- poj2975 Nim 胜利的方案数
Nim Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5545 Accepted: 2597 Description N ...
- poj2975(nim游戏取法)
求处于必胜状态有多少种走法. if( (g[i]^ans) <= g[i]) num++; //这步判断很巧妙 // // main.cpp // poj2975 // // Created b ...
- POJ2975 Nim 【博弈论】
DescriptionNim is a 2-player game featuring several piles of stones. Players alternate turns, and on ...
- POJ2975:Nim(Nim博弈)
Nim Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7279 Accepted: 3455 题目链接:http://p ...
- poj2975 Nim(经典博弈)
Nim Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5866 Accepted: 2777 Description N ...
- POJ2975 Nim 博弈论 尼姆博弈
http://poj.org/problem?id=2975 题目始终是ac的最大阻碍. 问只取一堆有多少方案可以使当前局面为先手必败. 显然由尼姆博弈的性质可以知道需要取石子使所有堆石子数异或和为0 ...
- [poj2975]Nim_博弈论
Nim poj-2975 题目大意:给定n堆石子,问:多少堆石子满足操作之后先手必胜. 注释:$1\le n\le 10^3$. 想法: 我们设M=sg(x1)^sg(x2)^...^sg(xn).其 ...
- [LeetCode] Nim Game 尼姆游戏
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
随机推荐
- 使用ngrok让微信公众平台通过80端口访问本机
最近在做微信开发,感觉测试不怎么方便,在网上找了找一下帖子,发现了这个好工具哈,与大家一同分享一下... 原文:http://blog.csdn.net/liuxiyangyang/article/d ...
- 关于group by
<pre name="code" class="sql">关于group by 排序问题 10g 以前sort group by 需要排序 10g ...
- 【转】Android通过JNI调用驱动程序(完全解析实例)
原文网址:http://blog.csdn.net/ok138ok/article/details/6560875 要达到的目的:android系统中,用JAVA写界面程序,调用jni中间库提供的接口 ...
- 【转】Ubuntu 修改hosts
原文网址:http://l.14551.org/2009/12/2166 Ubuntu系统的Hosts只需修改/etc/hosts文件,在目录中还有一个hosts.conf文件,刚开始还以为只需要修改 ...
- 【转】win7+ubuntu双系统安装方法--不错
原文网址:http://blog.csdn.net/lvanneo/article/details/16885121 前段时间又安装一下win7+ubuntu双系统,过段时间就会忘记,这次自己写下来, ...
- bzoj2346[Baltic 2011]Lamp
Description 2255是一个傻X,他连自己家灯不亮了都不知道. 某天TZ大神路过他家,发现了这一情况, 于是TZ开始行侠仗义了. TZ发现是电路板的问题, 他打开了电路板,发现线路根本没有连 ...
- hdu1573:数论,线性同余方程组
题目大意: 给定一个N ,m 找到小于N的 对于i=1....m,满足 x mod ai=bi 的 x 的数量. 分析 先求出 同余方程组 的最小解x0,然后 每增加lcm(a1...,am)都 ...
- shell输出加颜色
shell输出加颜色 #cat a.sh #!/bin/sh blue=`tput setaf 4` reset=`tput sgr0` echo "${blue}[INFORMATION] ...
- 无Root抓包:Packet Capture 1.2.3
无Root抓包:Packet Capture 1.2.3 http://www.coolapk.com/apk/app.greyshirts.sslcapture
- python calendar标准库基础学习
# -*- coding: utf-8 -*-# 作者:新手__author__ = 'Administrator'#标准库:日期时间基础学习:calendar:处理日期#例1import calen ...