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. 分析: 用矩阵记录 ...
随机推荐
- 夺命雷公狗---DEDECMS----23dedecms修改内容页面展示的信息
我们在网站上不管点击那个影视作品的A连接都是进入到一个同样的页面,因为他们是一个模版文件: 我们还没有对这个模版进行任何的修改,所以我们要在内容模版增加标签取出对应的影视作品,而且导航条也是按照模版上 ...
- CDC spyglass
SoC中会有着几百的clock domains,millions的async data crossing. Glitch等cdc问题是netlist level simulation的主要目的. CD ...
- [tp3.2.1]数据模型 - 简单的模型连接
新建数据库数据库连接功能 1.写conf.php /* 数据库设置 */ 'DB_TYPE' => '', // 数据库类 ...
- 【crunch bang】tint2配置2
# Tint2 config file # Background definitions # ID 1 rounded = 0 border_width = 0 background_color = ...
- WebSocket简单介绍
Java后端WebSocket的Tomcat实现 一.WebSocket简单介绍 随着互联网的发展,传统的HTTP协议已经很难满足Web应用日益复杂的需求了.近年来,随着HTML5的诞生,WebSoc ...
- Openstack的vnc界面定制
先来看一下青云的vnc界面: 在来看一下openstack的自带的vnc界面: 区别于感受 本身原理是一样的,但是vnc上面的html布局不一样而已,但是青云的vnc界面给人的感受是:清晰提示,信息给 ...
- OpenStack 镜像密码修改办法
Contents [hide] 1 场景 2 方案一 3 方案二 4 方案三 5 目前采用方案三 场景 用户将实例里的root密码修改了,/root/.ssh/的公钥文件删除了,然后把密码忘记了,需要 ...
- HDU4288:Coder(线段树单点更新版 && 暴力版)
Problem Description In mathematics and computer science, an algorithm describes a set of procedures ...
- android 学习随笔六(网络要求及配置)
android在4.0之后已经不允许在主线程执行http请求了. 主线程阻塞,应用会停止刷新界面,停止响应用户任何操作,耗时操作不要写在主线程 只有主线程才能修改UI ANR异常:Applicat ...
- android 学习随笔二(读写文件)
在android读写文件 RAM:运行内存,相当于电脑的内存 ROM:内部存储空间,相当电脑硬盘,android手机必须有的 SD卡:外部存储空间,相当电脑的移动硬盘,不是必须的.手机如果内置16G存 ...