3 条题解

  • 4
    @ 2023-8-26 21:14:16

    题目:

    设有一堆石子,数量为NN,两个人轮番取出其中的若干个,每次最多取MM个,最先把石子取完者胜利。

           \ \ \ \ \ \ \ 注意到石子数N=s(M+1)+rN=s(M+1)+r时,先行者只需取走rr个石子,令后行者面对s(M+1)s(M+1)的局面;无论后行者取走多少个石子,设其为xx(1xM)(1\le x\le M),先行者只需取走M+1xM+1-x个石子,令后行者继续面对s(M+1)s(M+1)的局面即可。最终后行者面对剩余M+1M+1个石子的局面时,无论如何都不可能取完,故先行者必胜。

           \ \ \ \ \ \ \ 类似地,若先行者一开始面对的就是N=s(M+1)N=s(M+1)的局面,则先行者必败。


    n = int(input())
    for _ in range(n):
        lst = list(map(int, input().split( )))
        if lst[0] % (lst[1] + 1):
            print('Win')
        else:
            print('Lose')
    
    • 0
      @ 2025-9-17 8:33:21

      实在猜不出来可以用sg函数来算

      from math import sqrt,ceil,gcd,log;re=lambda:map(int,input().strip().split())
      t, = re()
      for _ in range(t):
          n, m = re()
          print("Win" if n % (m + 1) else "Lose")
      
      • 0
        @ 2023-9-24 15:01:39

        //运用c语言博弈论也可以实现

        #include <stdio.h>
        int main()
        
        {
        
        int test_num, stone_num, max_fetch;
        
        scanf("%d", &test_num);
        
        while (test_num--)
        
        {
        
        scanf("%d%d", &stone_num, &max_fetch);
        
        if (stone_num % (max_fetch + 1) != 0)
        
        printf("Win\n");
        
        else
        
        printf("Lose\n");
        
        }
        
        return 0;
        
        }
        
        • 1

        信息

        ID
        126
        时间
        3000ms
        内存
        128MiB
        难度
        6
        标签
        (无)
        递交数
        1153
        已通过
        334
        上传者