zoukankan      html  css  js  c++  java
  • HackerRank

    HackerRank - powers-game-1 【博弈论】

    这里写图片描述

    这里写图片描述

    题意
    给出 * 2^1 * 2^2 * 2^3 * 2^4 * 2^5 * 2^n 这一串东西 ,然后有两个玩家,*号是可以被替换掉的东西,可以换成+ 或者 - 然后最后的式子求出来后MOD 17 如果最后的结果 == 0 则 P2 wins 否则 P1 wins

    思路
    因为MOD 17 根据同余定理,我们可以 在替换*号之前就MOD 比如

    2^1 2^2 2^3 2^4 2^5 2^6 2^7 2^8
    2 4 8 16 15 13 9 1

    然后我们发现 得到的都是一堆 0 - 15 的数字

    因为都是双方出的都是最优的策略

    我们发现 N = 8 的时候

    分别是
    1 16
    2 15
    4 13
    8 9

    这四组数据的特点是 相加都是 17

    玩家一先出 如果玩家一对某一个数 换号 玩家二只要对配套数换成相同符号 即可

    最后发现规律 只要N % 8 == 0 就是玩家二赢

    AC代码

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <cstring>
    #include <map>
    #include <stack>
    #include <set>
    #include <cstdlib>
    #include <ctype.h>
    #include <numeric>
    #include <sstream>
    using namespace std;
    typedef long long LL;
    const double PI = 3.14159265358979323846264338327;
    const double E  = 2.718281828459;  
    const int MAXN = 0x3f3f3f3f;
    const int MINN = 0xc0c0c0c0;
    const int maxn = 1e5 + 5;
    int main()
    {
        int t;
        cin >> t;
        while (t--)
        {
            int n;
            cin >> n;
            if (n % 8 ==0)
                cout << "Second
    ";
            else 
                cout << "First
    ";
        } 
    }
    
  • 相关阅读:
    创建windows服务
    Scrum演练(2)
    数据结构链表创建与输出
    C++ XML解析之tinyXML
    解决VS2010启动速度死慢的问题
    标准C++中string类的用法总结
    模版参数编译时检查方法,利用typedef
    static的作用
    数据结构实现链表的反转
    字节对齐
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433388.html
Copyright © 2011-2022 走看看