题意:对于一个给定的取石子游戏,有多少种先手策略获胜?

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的更多相关文章

  1. poj2975 Nim 胜利的方案数

    Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5545   Accepted: 2597 Description N ...

  2. poj2975(nim游戏取法)

    求处于必胜状态有多少种走法. if( (g[i]^ans) <= g[i]) num++; //这步判断很巧妙 // // main.cpp // poj2975 // // Created b ...

  3. POJ2975 Nim 【博弈论】

    DescriptionNim is a 2-player game featuring several piles of stones. Players alternate turns, and on ...

  4. POJ2975:Nim(Nim博弈)

    Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7279   Accepted: 3455 题目链接:http://p ...

  5. poj2975 Nim(经典博弈)

    Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5866   Accepted: 2777 Description N ...

  6. POJ2975 Nim 博弈论 尼姆博弈

    http://poj.org/problem?id=2975 题目始终是ac的最大阻碍. 问只取一堆有多少方案可以使当前局面为先手必败. 显然由尼姆博弈的性质可以知道需要取石子使所有堆石子数异或和为0 ...

  7. [poj2975]Nim_博弈论

    Nim poj-2975 题目大意:给定n堆石子,问:多少堆石子满足操作之后先手必胜. 注释:$1\le n\le 10^3$. 想法: 我们设M=sg(x1)^sg(x2)^...^sg(xn).其 ...

  8. [LeetCode] Nim Game 尼姆游戏

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  10. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

随机推荐

  1. VS2013中C++创建DLL导出class类

    1.创建"Win32 Console Application"项目,命名为"ClassDllLib",并在"Application type" ...

  2. c#发送邮件样例

    1.通过gmail邮箱发送邮件 try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(& ...

  3. 能取悦生理期的女性吗?Le Parcel提供女性卫生用品按月订购服务,不是按包出售而是可以按片自由搭配 | 36氪

    能取悦生理期的女性吗?Le Parcel提供女性卫生用品按月订购服务,不是按包出售而是可以按片自由搭配 | 36氪 能取悦生理期的女性吗?Le Parcel提供女性卫生用品按月订购服务,不是按包出售而 ...

  4. JavaScript Function 函数深入总结

    整理了JavaScript中函数Function的各种,感觉函数就是一大对象啊,各种知识点都能牵扯进来,不单单是 Function 这个本身原生的引用类型的各种用法,还包含执行环境,作用域,闭包,上下 ...

  5. HTML--鼠标事件

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  6. python3-day3(函数-参数)

    1.参数 函数的核心是参数传值,其次是返回值,熟练这两这个技术即可灵活使用函数. 1>普通参数 def  show(name): print(name) show('tom') 2>默认参 ...

  7. App上线流程全攻略(续)-iOS8之后的改动与所遇日常错误

    随着iOS8的公布,iTunes Connect的界面也是发生了非常大的改变,App 上传到 Store上面的步骤也是发生了些改变.以下继续用图说话: /*********************** ...

  8. HOG(方向梯度直方图)

    结合这周看的论文,我对这周研究的Histogram of oriented gradients(HOG)谈谈自己的理解: HOG descriptors 是应用在计算机视觉和图像处理领域,用于目标检測 ...

  9. SpringTest2

    Spring 框架第二天 AOP切面编程 今天重点内容: 1. 什么是AOP ? AOP实现原理是怎样的? AOP相关术语 2. AOP底层实现 (了解) ----- JDK动态代理. Cglib动态 ...

  10. (转)ie -ms-interpolation-mode: bicubic 属性详解

    ie -ms-interpolation-mode: bicubic 属性详解  img { -ms-interpolation-mode: bicubic; } 这个在做实时缩放图片.缩略图的时候用 ...