Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and Thave different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.

Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.

Help him do this!

Input

The first line contains integer n (1 ≤ n ≤ 200 000) — the length of strings S and T.

The second line contains string S.

The third line contains string T.

Each of the lines only contains lowercase Latin letters.

Output

In the first line, print number x — the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.

In the second line, either print the indexes i and j (1 ≤ i, j ≤ ni ≠ j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.

If there are multiple possible answers, print any of them.

Example

Input
9
pergament
permanent
Output
1
4 6
Input
6
wookie
cookie
Output
1
-1 -1
Input
4
petr
egor
Output
2
1 2
Input
6
double
bundle
Output
2
4 1

Note

In the second test it is acceptable to print i = 2, j = 3.

还是万年吐槽,这英语没救了。题目都看不懂的我和瞎子已经没有什么区别了。

题意:

给你两个长度为n的字符串,你有一次机会,将一个字符串的两个字母互换位置。

(要求:要使这两个字符串的元素不同的最少)

如果能互换使得不同之处变少,则输出互换后有多少个不同的元素,

并且输出所交换的元素的位置,如不能则输出-1 -1。

这题是一个非常灵活的思维题,如果思路简单则可以复杂度很小的求出答案。

如果是复杂的思路那就tle了。

这题亮点是用一个二维数组tu[30][30]去维护这两个字符串不同点。

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
char a[],b[];
int tu[][];
int main() {
while(scanf("%d%s%s",&n,a,b)!=EOF) {
int sum=;
memset(tu,,sizeof(tu));
for (int i= ; i<n ; i++ ) {
if (a[i]!=b[i]) {
tu[a[i]-'a'][b[i]-'a']=i+;
sum++;
}
}
int flag=;
if (flag) {
for (int i= ; i<n ; i++) {
if (a[i]!=b[i] && tu[b[i]-'a'][a[i]-'a']) {
printf("%d\n%d %d\n",sum-,tu[b[i]-'a'][a[i]-'a'],tu[a[i]-'a'][b[i]-'a']);
flag=;
break;
} }
}
if (flag) {
for (int i= ; i<n ; i++ ) {
if (a[i]!=b[i]) {
for (int j= ; j< ; j++) {
if (tu[b[i]-'a'][j]) {
printf("%d\n%d %d\n",sum-,tu[b[i]-'a'][j],i+);
flag=;
break;
}
}
if (flag==) break;
}
}
}
if (flag) printf("%d\n-1 -1\n",sum);
}
return ;
46}

Error Correct System CodeForces - 527B的更多相关文章

  1. CodeForces 527B Error Correct System

    Error Correct System Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I6 ...

  2. Codeforces Round #296 (Div. 2) B. Error Correct System

    B. Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. Error Correct System(模拟)

     Error Correct System Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  4. CF Error Correct System

    Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. B. Error Correct System (CF Round #296 (Div. 2))

    B. Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. 【codeforces 527B】Error Correct System

    [题目链接]:http://codeforces.com/contest/527/problem/B [题意] 给你两个字符串; 允许你交换一个字符串的两个字符一次: 问你这两个字符串最少会有多少个位 ...

  7. Codeforces Round #296 (Div. 2B. Error Correct System

    Ford Prefect got a job as a web developer for a small company that makes towels. His current work ta ...

  8. 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System

    题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...

  9. codeforce Error Correct System

    题目大意: 给出两串n(1 ≤ n ≤ 200 000)个字母的字符串, 求出最多交换一对数, 使得不相同对数变少,求出不相同的对数以及交换的数的位置,若不需交换则输出-1,-1. 分析: 用矩阵记录 ...

随机推荐

  1. [快速傅立叶变换&快速傅里叶变换]【旧 手写笔记】

    $FFT$好美啊 参考资料: 1.算法导论 2.Miskcoo 3.Menci 4.虚数的意义-阮一峰 简单说一下,具体在下面的图片 实现: 可以用$complex$也可以手写 和计算几何差不多 注意 ...

  2. 【深度学习】L1正则化和L2正则化

    在机器学习中,我们非常关心模型的预测能力,即模型在新数据上的表现,而不希望过拟合现象的的发生,我们通常使用正则化(regularization)技术来防止过拟合情况.正则化是机器学习中通过显式的控制模 ...

  3. Hot Research Topics

  4. Ubuntu 配置FTP服务器

    第三方的文件传输软件用着很不爽,想着自己搭建一个FTP来干活. 首先检查是否已经安装了FTP,输入命令: vsftpd -v  可以查看版本,如果没有安装,无法执行. 安装FTP p.p1 { mar ...

  5. 洛谷P1783 海滩防御 分析+题解代码

    洛谷P1783 海滩防御 分析+题解代码 题目描述: WLP同学最近迷上了一款网络联机对战游戏(终于知道为毛JOHNKRAM每天刷洛谷效率那么低了),但是他却为了这个游戏很苦恼,因为他在海边的造船厂和 ...

  6. angular ng build --prod 打包报错解决方案

    使用以下代码  就不报错了 ng build --prod --no-extract-license    打包命令 使用以下代码  就不报错了 ng build --prod --no-extrac ...

  7. mac中的myeclipse的控制台中文乱码问题解决办法

    之前写java用到控制台的主要是字符和数字,中文输入貌似真的还没用过,所以就遇到了一个悲剧的老问题,估计每个程序员都会遇到——中文乱码. 用的是MyEclipse开发环境,Window->Gen ...

  8. CSS 圣杯布局升级版---多个固定宽度一个自适应宽度

    1.一个div固定,一个div自适应宽度.两种情况,固定在左或者在右. HTML: <div class="box1"> <div class="mai ...

  9. lower_bound()返回值

    lower_bound()函数实现功能就是二分查找,函数lower_bound()在first和last中的前闭后开区间进行二分查找,返回大于或等于val的第一个元素位置.如果所有元素都小于val,则 ...

  10. Java版连连看

    连连看大家应该都玩过,不多说直接上一个做好的界面截图吧,所有的功能都在上面的,要做的就只是如何去实现它们了. 差不多就是这个样子.先说一下大致的思路吧.首先编写基本的界面:把什么按钮啊,表格啊什么的都 ...