Codeforces Round #169 (Div. 2), problem: (B) Little Girl and Game【久违的博弈题:可以排序的字符串回文问题】

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_42429718/article/details/102667058

Codeforces Round #169 (Div. 2), problem: (B) Little Girl and Game


题目大意

题目中说明字母的顺序可以打乱。即是说,abb可以重新排序成bab,构成回文,此时先手胜。


题解

博弈题

由于可以重新排列,然后双方又是最优选择,我们只需要考虑一下奇数个数的字母了,看有多少种,此时连忙想到了用mao维护一下,统计个数,最后我们只要判断一下奇数个字母的个数是否为奇数或者不存在奇数个字母,那么此时先手是必赢的,反之后手赢

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn=1e3+10;
char s[maxn];
map<char,int> mp;
map<char,int>::iterator it;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    int n=strlen(s);
    for(int i=0;i<n;i++)
        mp[s[i]]++;
    int odd=0;
    for(it=mp.begin();it!=mp.end();it++){
        if(it->second&1)
            odd++;
    }
    if(odd&1||!odd) cout<<"First"<<endl;
    else  cout<<"Second"<<endl;
    return 0;
}
学如逆水行舟,不进则退

猜你喜欢

转载自blog.csdn.net/weixin_42429718/article/details/102667058
今日推荐