Codeforces Round #498 (Div. 3) D. Two Strings Swaps
---恢复内容开始---
You are given two strings aa and bb consisting of lowercase English letters, both of length nn. The characters of both strings have indices from 11 to nn, inclusive.
You are allowed to do the following changes:
- Choose any index ii (1≤i≤n1≤i≤n) and swap characters aiai and bibi;
- Choose any index ii (1≤i≤n1≤i≤n) and swap characters aiai and an−i+1an−i+1;
- Choose any index ii (1≤i≤n1≤i≤n) and swap characters bibi and bn−i+1bn−i+1.
Note that if nn is odd, you are formally allowed to swap a⌈n2⌉a⌈n2⌉ with a⌈n2⌉a⌈n2⌉ (and the same with the string bb) but this move is useless. Also you can swap two equal characters but this operation is useless as well.
You have to make these strings equal by applying any number of changes described above, in any order. But it is obvious that it may be impossible to make two strings equal by these swaps.
In one preprocess move you can replace a character in aa with another character. In other words, in a single preprocess move you can choose any index ii (1≤i≤n1≤i≤n), any character cc and set ai:=cai:=c.
Your task is to find the minimum number of preprocess moves to apply in such a way that after them you can make strings aa and bb equal by applying some number of changes described in the list above.
Note that the number of changes you make after the preprocess moves does not matter. Also note that you cannot apply preprocess movesto the string bb or make any preprocess moves after the first change is made.
The first line of the input contains one integer nn (1≤n≤1051≤n≤105) — the length of strings aa and bb.
The second line contains the string aa consisting of exactly nn lowercase English letters.
The third line contains the string bb consisting of exactly nn lowercase English letters.
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string aa equal to string bb with a sequence of changes from the list above.
7
abacaba
bacabaa
4
5
zcabd
dbacz
分类讨论太菜了....蛮水的一道题
1 利用Map <char,int> 记录当前位置的字符种类,
1这种情况肯定不用说了
2 这种情况数量可能是 1 3 那么时候利用mp[s[i]]==2就可以判断是不是 1 3
3 这种情况是 1 1 2 这种情况
这种又分两种情况 那么就是 那么2 实在s1[]还是在 s2[], 由题意我们可以知道 只能改变s1[]来确保工作可以完成 因此如果2在s1[]的话,我们需要多加ans+=2;
4 ans+=2;
---恢复内容结束--

浙公网安备 33010602011771号