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;
    }
  • 相关阅读:
    POJ Problem 1363 Rails 【栈】
    POJ Problem 3040 Allowance 【贪心】
    ACM 程序对拍
    HDU Problem
    POJ
    HDU Problem
    HDU Problem—2124 Repair the Wall 【贪心】
    HDU Problem 1052 Tian Ji -- The Horse Racing 【贪心】
    POJ Problem Radar Installation 【贪心】
    Beyond Compare和输出文件比较的方法
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/11597877.html
Copyright © 2011-2022 走看看