【Codeforces 1006D】Two Strings Swaps

【链接】 我是链接,点我呀:)
【题意】


题意

【题解】


注意只能改变a不能改变b
然后只要让a[i],b[i],a[n-i-1],b[n-i-1]这4个字符能凑成两对、全都一样就可以了
分类讨论下就好

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 300;

int n;
string s1,s2;
map<char,int> dic,dic1;

int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    cin >> s1;
    cin >> s2;
    int cnt = 0;
    for (int i = 0;i < n/2;i++){
        dic.clear();dic1.clear();
        dic[s1[i]]++;
        dic[s1[n-i-1]]++;

        dic1[s2[i]]++;
        dic1[s2[n-i-1]]++;
        int k1 = dic.size(),k2 = dic1.size();
        if (k1==1 && k2==1){
            cnt+=0;
        }
        if (k1==1 && k2==2){
            dic1[s1[i]] = 1;
            int t = dic1.size();
            if (t==k2){
                cnt++;
            }else cnt+=2;
        }
        if (k1==2 && k2==1){
            dic[s2[i]] = 1;
            cnt++;
        }
        if (k1==2 && k2==2){
            dic[s2[i]] = 1;
            dic[s2[n-i-1]] = 1;
            int t = dic.size();
            if (t>k1+1){
                cnt+=2;
            }else if (t>k1){
                cnt++;
            }else cnt+=0;
        }
    }
    if (n%2==1){
        if (s1[n/2]!=s2[n/2]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/AWCXV/p/10696289.html
今日推荐