Triple Nim

Time Limit: 2000MS Memory limit: 65536K

题目描述

Alice and Bob are always playing all kinds of Nim games and Alice always goes first. Here is the rule of Nim game:

There are some distinct heaps of stones. On each turn, two players should remove at least one stone from just one heap. Two player will remove stone one after another. The player who remove the last stone of the last heap will win.

Alice always wins and Bob is very unhappy. So he decides to make a game which Alice will never win. He begins a game called “Triple Nim”, which is the Nim game with three heaps of stones. He’s good at Nim game but bad as math. With exactly N stones,
how many ways can he finish his target? Both Alice and Bob will play optimally.

输入

 Multiple test cases. The first line contains an integer T (T <= 100000), indicating the number of test case. Each case contains one line, an integer N (3 <= N <= 1000000000) indicating the number of stones Bob have.

输出

 One line per case. The number of ways Bob can make Alice never win.

示例输入

3
3
6
14

示例输出

0
1
4

提示

 In the third case, Bob can make three heaps (1,6,7), (2,5,7), (3,4,7) or (3,5,6).

来源

  “浪潮杯”山东省第七届ACM大学生程序设计竞赛

题意

应该是一道博弈的题目吧!因为自己没有看过博弈这方面的知识,听学长说,这道题目的意思就是给你一个数,把它拆分成三个数的和,并且这三个数异或值等于0,都是博弈的知识啦~
既然找三个数,并且这三个数的异或等于0,那么就要保证三个数的二进制对应位每一列必须有两个1,或者全是0.
可以分解成
的情况了,所以奇数一定不可能有这样的组合数,直接输出0.
若是偶数,它拆分之后的组合与本身二进制中1的个数有关。
14二进制中有三个1,而每一个1都是它分解成三个二进制数次位两个1相加进位得到的,也就是说,14这个数二进制有三个1,组合的情况便是3^3,减去三个数中某个数单独为0的情况3^3-3,又由于每种排列内部排序会出现A33这样的情况,所以要除去它
最终得出公式
ans=(3^m-3)/6 m为二进制中1的个数
这样便大功告成啦~,为了快捷,我们也可以对它进行打表

AC代码:
#include"stdio.h"
#include"string.h"
#include<iostream>
using namespace std;
long long s1(long long int n)   //求一个数二进制1的个数
{
    long long s=0;
    while(n>>=1)
        if(n&1)++s;
    return s-1;
}
long long f[30]= {1};
void init()                     //打表
{
    for(int i=1; i<30; i++)
        f[i]=f[i-1]*3+1;
}
int main()
{
    int N;
    init();
    cin>>N;
    while(N--)
    {
        long long int n;
        cin>>n;
        if(n&1)printf("0\n");
        else
        {
            long long int dd=s1(n)-1;
            cout<<f[dd]<<endl;
        }
    }
    return 0;
}

山东省第七届ACM省赛------Triple Nim的更多相关文章

  1. 山东省第七届ACM省赛------Memory Leak

    Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ...

  2. 山东省第七届ACM省赛------Reversed Words

    Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ...

  3. 山东省第七届ACM省赛------The Binding of Isaac

    The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ...

  4. 山东省第七届ACM省赛------Fibonacci

    Fibonacci Time Limit: 2000MS Memory limit: 131072K 题目描述 Fibonacci numbers are well-known as follow: ...

  5. 山东省第七届ACM省赛------Julyed

    Julyed Time Limit: 2000MS Memory limit: 65536K 题目描述 Julyed is preparing for her CET-6. She has N wor ...

  6. 山东省第七届ACM省赛

    ID Title Hint A Julyed 无 B Fibonacci 打表 C Proxy 最短路径 D Swiss-system tournament 归并排序 E The Binding of ...

  7. 山东省第十届ACM省赛参赛后的学期总结

    5.11,5.12两天的济南之旅结束了,我也参加了人生中第一次正式的acm比赛,虽然是以友情队的身份,但是我依旧十分兴奋. 其实一直想写博客来增加自己的能力的,但是一直拖到现在,正赶上老师要求写一份总 ...

  8. Rectangles(第七届ACM省赛原题+最长上升子序列)

    题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1255 描述 Given N (4 <= N <= 100)  rec ...

  9. 山东理工大学第七届ACM校赛-LCM的个数 分类: 比赛 2015-06-26 10:37 18人阅读 评论(0) 收藏

    LCM的个数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 对于我们来说求两个数的LCM(最小公倍数)是很容易的事,现在我遇到了 ...

随机推荐

  1. asp.net mvc 在视图中获取控制器与动作的名称

    获取 controller 名称: ViewContext.RouteData.Values["controller"].ToString(); 获取 action 名称: Vie ...

  2. Angular-ngtable联动全选

    之前于Angular第三方插件ngTable的官网demo上看到的例子,但苦于demo中联动全选为选中所有,项目中并不适用,因此做了下小小的修改,修改目的只是为实现其功能,方法不敢苟同,若有更加简便的 ...

  3. QQ战场形势图

    真是没什么可说,全面开战,无坚不摧,活脱脱一个中央帝国.只有极少的方向处于守势.本来对腾讯也没什么特别的感觉,但是看了这张图,真是让人热血沸腾. 如果美国的公司能像腾讯做的这么大相当于:faceboo ...

  4. ipxe引导远程的windows

    使用ipxe解决本地引导远程系统 本地安装的centos7,然后修改grub.cfg来使用ipxe技术引导远程windows,实现双系统 os-->centos7 修改grub.cfg 在文件最 ...

  5. 分享 rabbitMQ入门详解

    原文地址http://blog.csdn.net/cugb1004101218/article/details/21243927 目录(?)[-] rabbitMQ说明文档 rabbitMQ是什么 消 ...

  6. Android应用层View绘制流程与源码分析

    1  背景 还记得前面<Android应用setContentView与LayoutInflater加载解析机制源码分析>这篇文章吗?我们有分析到Activity中界面加载显示的基本流程原 ...

  7. postgresql查询的处理过程

    本文简单描述了Postgresql服务器接收到查询后到返回给客户端结果之间一般操作顺序,总的流程图如下: 第一步: 客户端程序可以是任何符合 PostgreSQL 协议规范的程序,如 JDBC 驱动. ...

  8. iOS APP开发的小知识(分享)

          亿合科技小编发现从2007年第一款智能手机横空出世,由此开启了人们的移动智能时代.我们从一开始对APP的陌生,到现在的爱不释手,可见APP开发的出现对我们的生活改变有多巨大.而iOS AP ...

  9. Last time, I wrote a pager, but now it seems this no longer has use, so I want to paste it here.

    public class Pager<T> where T : new() { private IEnumerable<T> _all; private IEnumerable ...

  10. C# 利用SQLite对.DB和.logdb加密和解密和SQLite创建数据库

    1.最近研究了下利用SQLite为db文件简单的加密和解密 private static SQLiteConnection GetConnection() { SQLiteConnection con ...