我是真的菜,嗯,这是题解开篇辟邪的。
今天又开始做CF,一开始看题没明白题意,后来就是思路错了,演绎法用的太差,没有考察到足够的例子。就开始形成算法,或者没有论证自己的算法。再就是思考的方向不对。当思考的方向更正时,发现自己又被技术所限制,唉,真是菜。
先来说一下,我认为的问题的第一个关键所在,就是统计a[i],b[i],b[n - 1 - i],a[n - 1 - i]的关系,具体来说先统计每种字符出现的个数,看了题解是使用map统计的。 很强势。学习一下。
以下转载自
https://blog.youkuaiyun.com/x_flyx/article/details/81101447
#include<cstdio>
#include<iostream>
#include<queue>
#include<string>
#include<map>
using namespace std;
typedef long long LL;
int main()
{
int n;
ios::sync_with_stdio(false);
while(cin >> n)
{
string a,b;
cin >> a >> b;
int ans = 0;
int t = n;
n = n - 1;
for(int i = 0;i < t / 2;++i)
{
map<char,int> m;
m[a[i]]++,m[b[i]]++;
m[a[n - i]],m[b[n - i]]++;
if(m.size() == 4) ans += 2;
if(m.size() == 3) ans += 1 + (a[i] == a[n - i]);
if(m.size() == 2) ans += (m[a[i]] != 2);
}
if(t&1 && a[t/2] != b[t/2]) ans++;
cout << ans << endl;
}
return 0;
}