Description

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 T have 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 ≤ n, i ≠ 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.

Sample Input

.input, .output {border: 1px solid #888888;} .output {margin-bottom:1em;position:relative;top:-1px;} .output pre,.input pre {background-color:#EFEFEF;line-height:1.25em;margin:0;padding:0.25em;} .title {background-color:#FFFFFF;border-bottom: 1px solid #888888;font-family:arial;font-weight:bold;padding:0.25em;}

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

Sample Output

 

Hint

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

解题思路:

题目大意:给两个长度相等的字符串,统计不同字符位置的个数,同时允许交换一组字符位置,使字符串相似度最高,要求输出交换后的距离(不同个数),以及交换的位置,如果没有交换的必要则输出-1 -1。

用一个二维数组存储两不同字符的位置:Map[i][j]=loca(loca位置的俩字符i与j不同)

有三种情况:交换一次,交换的两个位置都完全匹配;交换一次,一个位置匹配;不交换。

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
#define Max 200005
int Map[][];
int p1=-,p2=-;
int main()
{
string a,b;
int n,count=;
cin>>n;
cin>>a>>b;
memset(Map,-,sizeof(Map));
for(int j=;j<n;j++)
{
if(a[j]!=b[j])
{
Map[a[j]-'a'][b[j]-'a']=j;
count=count+;
}
}
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(Map[i][j]!=-&&Map[j][i]!=-)
{
p1=Map[i][j]+;
p2=Map[j][i]+;
count=count-;
printf("%d\n",count);
printf("%d %d\n",p1,p2);
return ;
}
}
}
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
for(int k=;k<;k++)
{
if(Map[i][j]!=-&&Map[j][k]!=-)
{
p1=Map[i][j]+;
p2=Map[j][k]+;
count=count-;
printf("%d\n",count);
printf("%d %d\n",p1,p2);
return ;
}
}
}
}
printf("%d\n",count);
printf("%d %d\n",p1,p2);
return ;
}

CodeForces 527B的更多相关文章

  1. CodeForces 527B Error Correct System

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

  2. 【codeforces 527B】Error Correct System

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

  3. Error Correct System CodeForces - 527B

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

  4. Error Correct System(模拟)

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

  5. Codeforces Round #527-B. Teams Forming(贪心)

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  6. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  9. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

随机推荐

  1. Visual C#使用DirectX实现视频播放

    Visual C#使用DirectX实现视频播放 visual|视频播放 - 很多人第一次接触到DirectX大都是通过游戏,至于安装.升级DirectX的原因无非是满足游戏运行的需要.Direct ...

  2. (Map)利用Map,完成下面的功能:  从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。如果该 年没有举办世界杯,则输出:没有举办世界杯。  附:世界杯冠军以及对应的夺冠年份,请参考本章附录。 附录 (Map)在原有世界杯Map 的基础上,增加如下功能: 读入一支球队的名字,输出该球队夺冠的年份列表。 例如,读入“巴西”,应当输出 1958 1962 1970 1

    package homework001; import java.util.HashMap; import java.util.Scanner; public class Map { public s ...

  3. mycat表拆分操作教程

    1,迁移数据 举例说明,比如一个博客数据库数据表如下: 这里水平拆分,垂直拆分,只是做个简单的实验,真正的线上业务要根据情况,数据进行拆分. ? 1 2 3 4 5 6 7 8 9 10 11 12 ...

  4. 2016 Mac OS 10.11 CocoaPods的安装问题

    CocoaPods的安装问题: 1.首先用淘宝的Ruby镜像来访问CocoaPods,打开终端输入以下命令: (1)gem sources --remove  https://rubygems.org ...

  5. MATLAB学习拾遗

    1.坐标轴修饰 axis equal:axis([0,6,0,6]) 不修饰则为默认网格 grid on 2.不太漂亮的pretty命令 3. Laplace变换 syms t s a b f1=ex ...

  6. XMPP——Smack[2]会话、消息监听、字体表情和聊天窗口控制

    连接之后,拿到了connection,通过它可以搞定会话 建立一个会话 MessageListener msgListener = new MessageListener() { public voi ...

  7. SQL Server磁盘I/O性能分析

    SQL Server中的I/O操作类型: 1.对于内存中没有缓存的数据,第一次访问时需要将数据从所在的页面从数据文件中读取到内存中 2.在任何Insert/Update/Delete提交前,SQL S ...

  8. IOS开发-加载本地音乐

    IOS开发-加载本地音乐 $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text() ...

  9. ABAP程序执行效率和优化 ABAP Performance Examples

    一.             SQL Interface1.         Select ... Where vs. Select + Check用Select … Where语句效率比Select ...

  10. (转)如何在JavaScript与ActiveX之间传递数据3

    本文研究如何在JS等脚本语言与ActiveX控件之间通信,如何传递各种类型的参数,以及COM的IDispatch接口.使用类似的方法,可以推广到其他所有脚本型语言,如LUA,AutoCad等.本文将研 ...