超级码力在线编程大赛初赛 第3场 3.字符串游戏(Anti-Nim)

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);
    }
};

 

posted @ 2020-09-19 14:21  TRTTG  阅读(255)  评论(0编辑  收藏  举报