zoukankan      html  css  js  c++  java
  • Codeforces 1194D. 1-2-K Game

    传送门

    先考虑只能走 $1,2$ 步的情况,设 $p[i]$ 表示当 $n=i$ 时先手是否必胜

    自己手玩一下发现 $p$ 就是 $011011011...011$ 这样循环(下标从 $0$ 开始,其中 $1$ 表示先手必胜)

    然后发现当 $K$ 不是 $3$ 的倍数时,对 $p$ 没有影响,因为一个必败局面仍然只能到达必胜局面,必胜局面仍然可以到达必败局面

    然后考虑 $K$ 为 $3$ 的倍数时,那么 $p[K]$ 就从 $0$ 变成了 $1$,之后从 $p[K+1]$ 开始又是一段 $011011...011$ 直到 $p[2K]$

    所以根据找到的规律判断即可

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    using namespace std;
    typedef long long ll;
    inline int read()
    {
        int x=0,f=1; char ch=getchar();
        while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
        while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
        return x*f;
    }
    int main()
    {
        int Q,n,m;
        Q=read();
        while(Q--)
        {
            n=read(),m=read();
            if(m%3||n<m) { if(n%3) printf("Alice
    "); else printf("Bob
    "); continue; }
            if(n==m) { printf("Alice
    "); continue; }
            if(n%(m+1)==m) printf("Alice
    ");
            else if((n%(m+1))%3) printf("Alice
    ");
            else printf("Bob
    ");
        }
        return 0;
    }
  • 相关阅读:
    Mybatis一级缓存和二级缓存总结
    UML模型的基本概念
    Proxy patten 代理模式
    UML 基础:类图
    Java与UML交互图
    Composite Pattern (组合模式)
    用例建模指南
    Prototype Pattern(原型模式)
    Adapter Pattern(适配器模式)
    UML 类与类之间的关系
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/11597877.html
Copyright © 2011-2022 走看看