B. Error Correct System
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ≤ 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.

Sample test(s)
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.

题意:交换S或者T中的两个字符。使得两串的差异度最小。有三种情况,一种是交换后正好两个位置都相应同样,一种是交换后仅仅有一个位置同样,还有就是交换也不能满足相应同样。

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#define N 2222
using namespace std; char s[200009],t[200009];
int n;
int a[N][N]; int main()
{
while(~scanf("%d",&n))
{
scanf("%s %s",s,t); int num=0;
memset(a,0,sizeof a); for(int i=0;i<n;i++)
if(s[i]!=t[i])
{
int x=s[i]-'a';
int y=t[i]-'a';
num++;
a[x][y]=i+1;
} for(int i=0;i<26;i++)//交换后两位置都相应同样了
for(int j=0;j<26;j++)
if(a[i][j] && a[j][i])
{
cout<<num-2<<endl;
cout<<a[i][j]<<" "<<a[j][i]<<endl;
return 0;
} for(int i=0;i<26;i++)//交换后仅仅有一个位置相应同样
for(int j=0;j<26;j++)
if(a[i][j])
{
for(int k=0;k<26;k++)
if(a[j][k])
{
cout<<num-1<<endl;
cout<<a[i][j]<<" "<<a[j][k]<<endl;
return 0;
}
} cout<<num<<endl;
cout<<-1<<" "<<-1<<endl;//无法通过交换降低差异度 }
return 0;
}

Codeforces Round #296 (Div. 2) B. Error Correct System的更多相关文章

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

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

  2. Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路

    Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xx ...

  3. CodeForces Round #296 Div.2

    A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...

  4. 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 ...

  5. Codeforces Round #296 (Div. 1) E. Triangles 3000

    http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...

  6. 水题 Codeforces Round #296 (Div. 2) A. Playing with Paper

    题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...

  7. Codeforces Round #296 (Div. 2) A. Playing with Paper

    A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an o ...

  8. Codeforces Round #296 (Div. 2) A B C D

    A:模拟辗转相除法时记录答案 B:3种情况:能降低2,能降低1.不能降低分别考虑清楚 C:利用一个set和一个multiset,把行列分开考虑.利用set自带的排序和查询.每次把对应的块拿出来分成两块 ...

  9. Codeforces Round #296 (Div. 1) B - Clique Problem

    B - Clique Problem 题目大意:给你坐标轴上n个点,每个点的权值为wi,两个点之间有边当且仅当 |xi - xj| >= wi + wj, 问你两两之间都有边的最大点集的大小. ...

随机推荐

  1. Intellij IDEA 14使用maven3.3.3 问题

    Intellij IDEA 14使用maven3.3.3报错: -Dmaven.multiModuleProjectDirectory system propery is not set. Check ...

  2. 虚拟机VMware下CentOS6.5安装教程图文详解(VMnet8)

    (写在最前面:如果你下载的iso文件 CentOS-6.*-x86_64-minimal.iso 系列,那么需要这么安装:https://blog.csdn.net/lixianlin/article ...

  3. mysql root用户密码个性

    对名为“mysql”数据库下的表“user”进行操作如下语句:update user set password=PASSWORD("your_password") where us ...

  4. C#:XML操作(简单)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  5. 流类库继承体系(IO流,文件流,串流)和 字符串流的基本操作

    一.IO.流 数据的输入和输出(input/output简写为I/O) 对标准输入设备和标准输出设备的输入输出简称为标准I/O 对在外存磁盘上文件的输入输出简称为文件I/O 对内存中指定的字符串存储空 ...

  6. 交叉编译Node.js到OpenWrt(HG255D)

    操作系统:deepin linux 2013 或 ubuntu 13.04 1.安装交叉编译前.须要安装的包 sudo apt-get install build-essential subversi ...

  7. atitit.设计文档---操作日志的实现

    atitit.设计文档---操作日志的实现 日志查询 1 ----mybatis  配置... 1 添加日志 1 日志查询 <a class="l-link" href=&q ...

  8. location [=|$|最长原则|^~](nginx-1.4.4)

    优先级由上到下依次递减: location =/a/1.png { return 400; } } location ~* \.png$ { return 403; } location /a/1.p ...

  9. Django Rest Framework(分页、视图、路由、渲染器)

    一.分页 试问如果当数据量特别大的时候,你是怎么解决分页的? 方式a.记录当前访问页数的数据id 方式b.最多显示120页等 方式c.只显示上一页,下一页,不让选择页码,对页码进行加密 1.基于lim ...

  10. 解决VisualStudio2013无法查看数组内容的问题

    症状: 在使用VS2013调试的时候,数组只能查看第一个元素的值.如图 解决方案: 调试>窗口>内存 输入数组的内存地址,右击内存窗口>带符号显示(也可以选择16进制显示,看你自己的 ...