360笔试

1.

偶串:

用二进制表示每个字母出现的奇偶性,在采用类似前缀和的方法求解。

#include <bits/stdc++.h>
#define maxn 100009
using namespace std;
char s[maxn];
map<int,int>mp;
int n;
int main(){
    scanf("%s",s);
    n = strlen(s);
    mp[0] = 1;
    int cur = 0;
    long long ans = 0;
    for(int i = 0; i < n; i++){
        int x = s[i] - 'a';
        cur ^= (1 << x);
        ans += mp[cur];
        mp[cur]++;
    }
    cout << ans << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/simplepaul/p/6618960.html