CodeForces 527B Error Correct System
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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
9
pergament
permanent
1
4 6
6
wookie
cookie
1
-1 -1
4
petr
egor
2
1 2
6
double
bundle
2
4 1
Hint
In the second test it is acceptable to print i = 2, j = 3.
#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std; char l1[],l2[];
vector <int> x[];
vector <int> y[]; int main()
{
int n,p,q;
int i,j,k;
while(scanf("%d",&n)!=EOF)
{
scanf("%s",l1+);
scanf("%s",l2+);
for(i=;i<=;i++)
{
x[i].clear();
y[i].clear();
}
p=-,q=-;
int flg=,s=;
for(i=;i<=n;i++)
{
if(l1[i]!=l2[i])
{
if(flg==)
{
if(x[l2[i]-'a'+].size()>)
p=x[l2[i]-'a'+][],q=i,flg=;
else if(y[l1[i]-'a'+].size()>)
p=y[l1[i]-'a'+][],q=i,flg=;
}
if(flg!=)
{
for(j=;j<x[l2[i]-'a'+].size();j++)
{
k=x[l2[i]-'a'+][j];
if(l2[k]==l1[i])
{
p=k,q=i,flg=;
break;
}
}
}
s++;
x[l1[i]-'a'+].push_back(i);
y[l2[i]-'a'+].push_back(i);
}
}
printf("%d\n",s-flg);
printf("%d %d\n",p,q);
}
return ;
}
CodeForces 527B Error Correct System的更多相关文章
- 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 ...
- Error Correct System(模拟)
Error Correct System Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- CF Error Correct System
Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 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 ...
- 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 ...
- 【codeforces 527B】Error Correct System
[题目链接]:http://codeforces.com/contest/527/problem/B [题意] 给你两个字符串; 允许你交换一个字符串的两个字符一次: 问你这两个字符串最少会有多少个位 ...
- 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 ...
- 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System
题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...
- codeforce Error Correct System
题目大意: 给出两串n(1 ≤ n ≤ 200 000)个字母的字符串, 求出最多交换一对数, 使得不相同对数变少,求出不相同的对数以及交换的数的位置,若不需交换则输出-1,-1. 分析: 用矩阵记录 ...
随机推荐
- 夺命雷公狗—angularjs—17—angularjs的静态库
在实际的开发中我们往往已经离不开我们的静态库了,因为那里面有太多强悍的功能了,比如路由都是通过一个angular-route的库来实现的,, 那个库,我们可以在百度静态资源公共库来查找,查找方法如下所 ...
- 夺命雷公狗—angularjs—5—ng-switch的用法实现下拉更换板块的实现
这个方法一般都会是和别的块状元素进行绑定同时使用的,废话不多说,直接上代码: <!doctype html> <html lang="en"> <he ...
- 由ccf第一题引出的问题
当时的情况是这样的,代码中需要用到一个较大的二维数组,但只要定义这个大二维数组编译就出错,无奈后来用malloc自己实现了类似二维数组的操作. 其中的b数组设为全局的或者静态的也都可以解决overfl ...
- 【php】目录、路径和文件 操作
目录操作 解析路径: basename() - 返回路径的文件名部分 获取目录部分: dirname() - 返回路径的目录部分 路径信息: pathinfo() - 返回数组(目录名,基本名,扩展名 ...
- SQL SERVER 2008 R2配置管理器出现“远程过程调用失败”【0x800706be】的解决办法
以前SQL Server 2008 不能登陆的时候,总是通过“计算机管理”→“SQL Server服务”更改一下,"SQL Server(MSSQLSERVER)".可是现在出现的 ...
- 《Focus On 3D Terrain Programming》中一段代码的注释一
取自<Focus On 3D Terrain Programming>中的一段: //--------------------------------------------------- ...
- android 设置Button或者ImageButton的背景透明 半透明 透明
Button或者ImageButton的背景设为透明或者半透明 半透明<Button android:background="#e0000000" ... /> 透明 ...
- js正则函数match、exec、test、search、replace、split使用介绍集合
match 方法 使用正则表达式模式对字符串执行查找,并将包含查找的结果作为数组返回. stringObj.match(rgExp) 参数 stringObj 必选项.对其进行查找的 String 对 ...
- php curl应该怎么使用呢
原php默认并不进行此项功能的扩展,但还是有的,只是没有让它生效罢了.打开PHP安装目录,搜索以下三个文件 ssleay32.dll.libeay32.dll和 php_ curl .dll,一一拷贝 ...
- mime类型表
types { text/html html htm shtml; text/css ...