https://tianchi.aliyun.com/oj/15179470890799741/85251759933690469

 

问题可以转化为由若干堆石子,每次可以从一堆中取走若干个,取走最后一个的输

Anti-Nim游戏

结论及证明:

https://www.cnblogs.com/TheRoadToTheGold/p/6744825.html

 

class Solution {
public:
    /**
     * @param s: a string for this game 
     * @return: return whether Alice can win this game
     */
    
    int sum[27];
     
    bool stringGame(string &s) {
        // Write your code here.
        int n=s.length();
        for(int i=0;i<n;++i)
            sum[s[i]-'a']++;
        int sg=0;
        bool mtwo=false;
        for(int i=0;i<26;++i)
        {
            if(sum[i]>=2) mtwo=true;
            sg^=sum[i];
        }
        if(sg) sg=1;
        return !(sg^mtwo);
    }
};

 

相关文章:

  • 2021-10-31
  • 2021-11-30
  • 2021-11-05
  • 2022-12-23
  • 2021-11-08
  • 2022-02-22
  • 2021-07-28
  • 2021-05-23
猜你喜欢
  • 2022-02-24
  • 2021-12-10
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2022-01-07
相关资源
相似解决方案