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. 具有SSM框架的CRUD与多条件查询

    概述 居于ssm版本的crud跟多添加查询, 并带分页的demo 详细 代码下载:http://www.demodashi.com/demo/13653.html 一.功能展示 部门CRUD: 员工C ...

  2. Docker实战(五)编写Dockerfile

    一.创建Dockerfile文件 首先,需要创建一个目录来存放 Dockerfile 文件,目录名称可以任意,在目录里创建Dockerfile文件: 二.Dockerfile 基本框架 Dockerf ...

  3. post请求乱码

    jsp页面中    <meta http-equiv="content-type" content="text/html; charset=UTF-8"& ...

  4. List、Set、Map常见集合遍历总结

    Java中的集合有三大类,List.Set.Map,都处于java.util包中,List.Set和Map都是接口,不能被实例化,它们的各自的实现类可以被实例化.List的实现类主要有ArrayLis ...

  5. C# : 连接SDE空间数据库时出错

    1.SDE认证问题:使用ArcGIS.KeyGen.exe生成一个epp文件方法:-->server-->All-->拷贝并保存为*.epp文件.认证时加载该文件即可认证完毕.2.实 ...

  6. Android Context原理与使用的总结

    一.Context继承体系 与 Context是怎样创建的 1. Context继承体系 仅仅用记住一句:Activity . Service 与Application 都是继承自ContextWra ...

  7. 用sp_lock诊断SQL Sever的死锁问题

    找出什么被锁定了 系统的反应迟缓意味着你应该做一些调查了.你的查找最好从测定系统发生锁定的数量和频率开始.如果你的系统环境处理事务性很高的话,这样各个应用程序争夺资源就会很常见,从而引起锁定.解决这些 ...

  8. django admin 如何去掉s 如何去掉django admin 各个模块后面的s

    其中加上红色标记的内容,业务管理员后面就不会有 s 了 class UsrMngUser(models.Model): user_name = models.CharField("用户名称& ...

  9. docker容器跑tomcat遇到的坑

    使用docker容器跑tomcat,由于同一个宿主机上跑了多个容器,再加上宿主机本身跑了很多进程,导致系统总的进程数达到了8000+,而容器中tomcat的启动脚本中会调用自带的setenv.sh,在 ...

  10. python (18)在linux中如何实现定时发送邮件到指定邮箱,监测任务

    最近要用到,定时发送邮件功能: 如何定时,当然要用到linux中crontab了 如下的代码能够定时发送邮件 #!/usr/bin/env python # -*- coding=utf-8 -*- ...