zoukankan      html  css  js  c++  java
  • 第七届 山东省ACM Triple Nim(找规律 待整理)

    Triple Nim

    Time Limit: 2000MS Memory Limit: 65536KB

    Problem Description

    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.

    Input

     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.

    Output

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

    Example Input

    33614

    Example Output

    014

    Hint

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

    Author

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

    题意:给你n个石子,分成三堆,计算通过Nim博弈的规则使得对方不能获胜的方案数。

    思路:打表找规律题,不解释。

    参考网址:http://blog.csdn.net/huayunhualuo/article/details/51626212

    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long LL;
    
    int main()
    {
        int T;
    
        LL n;
    
        scanf("%d",&T);
    
        while(T--)
        {
            scanf("%lld",&n);
    
            if(n%2) printf("0
    ");
            else 
            {
                int s = 0 ;
                while(n)
                {
                    if(n%2) s++;
    
                    n/=2;
                }
    
                LL ans = (LL(pow(3,s))-3)/6;
    
                printf("%lld
    ",ans);
            }
        }
        return 0;
    }







  • 相关阅读:
    Python 使用ASE加密与解密
    21年我的目标
    Python使用struct模块发送字节数据解析协议
    强大的awk,解决liunx中解决浮点数计算
    没错,这是我20年正式总结
    2020年度总结--杂谈,不是技术文章
    libcurl 工具类
    【C++开源库】Windows 下编译 libcurl 库
    Qt 封装HTTP网络工具类HttpClient
    Qt 访问网络
  • 原文地址:https://www.cnblogs.com/zswbky/p/6717881.html
Copyright © 2011-2022 走看看