zoukankan      html  css  js  c++  java
  • EOJ 1068 石子游戏-B

    http://acm.cs.ecnu.edu.cn/problem.php?problemid=1068

    题意:

      该题比一般的NIMM博弈多了每次取1-m个的限制,容易联想到巴什博奕。

    解题思路:

      把每堆数量减少到<=m,使之转化为无限制的NIMM博弈。

      设第 i 堆有ki*(m+1)+si (0 <= si < m+1)个石子,只需判断STATE = (k1*(m+1)+s1, ...ki*(m+1)+si, ...,kn*(m+1)+sn)的状态。

      设对应的state =(s1, ... si, ..., sn),  nim_sum(state) = s1^s2^...^sn;

      1. 若nim_sum(state) = 0, 则state为必败态,由巴什博奕,得 STATE 为必败态。

      //2. 若nim_sum(state) != 0, 则state为必胜态,由巴什博奕,得 STATE 为必胜态。

        2好像写的不对,改一改:

      2.第一步应该使得nim_sum(state)变为零,即把必败态留给对方,具体做法:

      若nim_sum(state) = c != 0,c的最高位为p, 则存在st, 其最高位也为p。令x = c^st, 有 x < st。把 st 变为 x 即可。

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string>
     4 #include <algorithm>
     5 #include <string.h>
     6 #include <stdlib.h>
     7 
     8 using namespace std;
     9 
    10 int main()
    11 {
    12     //freopen("testin.txt", "r", stdin);
    13     //freopen("testout.txt", "w", stdout);
    14     
    15     int t;
    16     cin >> t;
    17     while(t--)
    18     {
    19         int a = 0;
    20         int n, m;
    21         cin >> n >> m;
    22         
    23         //cout << n << m; 
    24         
    25         while(n--)
    26         {
    27             int x;
    28             cin >> x;
    29             a ^= (x%(m+1)); 
    30         }
    31         if(a)
    32             printf("Win
    ");//先手者。 
    33         else
    34             printf("Lost
    ");
    35     }
    36    
    37     return 0;
    38 }
    View Code

      

      

  • 相关阅读:
    CF1391D 【505】
    CF1389C 【Good String】
    CF1364C 【Ehab and Prefix MEXs】
    CF1353E 【K-periodic Garland】
    CF1349A 【Orac and LCM】
    CF1352C 【K-th Not Divisible by n】
    CF413D 【2048】
    CF257B 【Playing Cubes】
    CF267A 【Subtractions】
    2018.8.16提高B组模拟考试
  • 原文地址:https://www.cnblogs.com/KimKyeYu/p/3176785.html
Copyright © 2011-2022 走看看