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. JavaScript语言学习中的注意事项

    javascript: 基于浏览器 基于对象 事件驱动 脚本语言 由: javascript: ECMAscript(ES) DOM文档对象模型 BOM浏览器对象模型,三部分组成 使用js的三种方式 ...

  2. php读取文件内容的三种方法

    <?php //**************第一种读取方式***************************** 代码如下: header("content-type:text/h ...

  3. hbuilder ios 打包失败,无法导入p12证书的解决方案

    问题描述: 在profile文件和私钥证书通过hbuilder ios 打包成功过的前提下,突然遇到打包失败的问题,问题详情是无法导入p12证书. 探索过程: 本着遇到问题先自省的态度,重复打包了几次 ...

  4. bower使用入门

    1.什么是bower Bower是一个客户端技术的软件包管理器,它可用于搜索.安装和卸载如JavaScript.HTML.CSS之类的网络资源.其他一些建立在Bower基础之上的开发工具,如YeoMa ...

  5. 借助Maven入手Spring Boot第一个程序

    目前网上有不少Spring Boot的入门文章,都很有帮助,本人最近在深入学习Spring Cloud,在搭建第一个Hello World程序时,感觉对于新手而言,介绍文章怎么详细都不为过,因为其中坑 ...

  6. mysql有多条记录的单个字段想存为一个字段显示的方法

    SELECT po.id,(SELECT GROUP_CONCAT(mr.member_type) as memberTypeList FROM prod_offer_member_rel mr WH ...

  7. Thinkpad USB 经典键盘使用体验

    先上图,这就是一个键盘,不是笔记本电脑. 优点: 1. 键盘完胜各类巧克力式键盘. 2. 小红点和老thinkpad 上的小红点一样好用. 3. ESC 和Delete 放大后,盲摸很方便. 缺点: ...

  8. C++ 11 左值,右值,左值引用,右值引用,std::move, std::foward

    这篇文章要介绍的内容和标题一致,关于C++ 11中的这几个特性网上介绍的文章很多,看了一些之后想把几个比较关键的点总结记录一下,文章比较长.给出了很多代码示例,都是编译运行测试过的,希望能用这些帮助理 ...

  9. hibernate学习(六) flush()和clean()区别和使用

    session.flush()是强制和数据库同步 session.clean()是清除session中的缓存 对于批量数据插入的时候优化:减少cpu和内存(缓存)占用量 @Test public vo ...

  10. TensorFlow4Delphi

    https://github.com/hartmutdavid/TensorFlow4Delphi