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. JavaScript 原型继承开端

    1.原型继承本质       就javascript对象系统的实现来讲,对象并没有原型,而构造器有原型(构造器.prototype指向其原型).对象只有构造自某个原型的说法,并没有持有某个原型的说法. ...

  2. java System 常用方法

    一.System.currentTimeMillis() 获取系统当前时间,毫秒 二.System.getProperty Java.version Java 运行时环境版本 java.vendor ...

  3. android studio 更改背景和设置字体大小

    1,设置字体大小 2,设置背景主题

  4. MFC 学习 之 状态栏的添加

    1.首先声明一个 CStatusBar  m_bar;//声明对象2.然后打开视图资源 String Table中添加两个字段值 3.创建了两个字段值以后,在OnintDialog() 所在的 .cp ...

  5. Codeforces Round #319 (Div. 1) B. Invariance of Tree 构造

    B. Invariance of Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/ ...

  6. Web API接口 安全验证

    在上篇随笔<Web API应用架构设计分析(1)>,我对Web API的各种应用架构进行了概括性的分析和设计,Web API 是一种应用接口框架,它能够构建HTTP服务以支撑更广泛的客户端 ...

  7. 2013 ACM/ICPC Asia Regional Changsha Online J Candies

    AC了,但是不知道为什么,但是恶心的不得了~最近写代码,思路都非常清晰,但是代码各种bug~T.T~说说思路吧:二分~330ms~ 小队友fribbi的思路是离线250msAC~ 预处理solve函数 ...

  8. WIX在VS2012中如何制作中文安装包

    WIX安装图文并茂简易说明一文中介绍了WIX安装包的制作过程,不过生成的是英文版的,如果需要制作中文版的安装包呢? 方法很简单,只需要两步. 1.增加中文UI的文件WixUI_zh-cn.wxl到工程 ...

  9. [React Fundamentals] Using Refs to Access Components

    When you are using React components you need to be able to access specific references to individual ...

  10. android学习日记06--View视图

    一.android 界面开发 1.三个重要的类:View视图.Canvas画布.Paint画笔2.android 界面开发常用三种视图 View            --只能在主线程中更新,没有缓存 ...