2017-ccpc杭州现场赛

 补题中  -  ing ....

A.Super-palindrome

原题链接:HDU - 6264

思路:由于题中给出奇数子串全是回文串,所以对应1,3,5,7... 奇数位置的字符应该相同,同理偶数位置的字符同样应该相同。所以我们只需要找到奇数位置与偶数中出现次数最大的个数,用总数去减即可。

#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int cnt[28];
int tot[28];
string s;
int cmp(int a,int b){
    if(a>b) return 1;
    else return 0;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        cin>>s;
        int len = s.size();
        memset(cnt,0,sizeof(cnt));
        memset(tot,0,sizeof(tot));
        for(int i=0;i<len;i++){
            if((i+1)&1) cnt[s[i]-'a']++;
            else tot[s[i]-'a']++;
        }
        sort(cnt,cnt+26,cmp);
        sort(tot,tot+26,cmp);
        cout<<len-cnt[0]-tot[0]<<endl;
    }
}
View Code

C.Hakase and Nano思路:本弱鸡靠找规律得的结果...

题解:2017CCPC杭州-C. Hakase and Nano

原文地址:https://www.cnblogs.com/Tianwell/p/11469127.html