Error Correct System CodeForces - 527B
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 Thave 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.
Example
9
pergament
permanent
1
4 6
6
wookie
cookie
1
-1 -1
4
petr
egor
2
1 2
6
double
bundle
2
4 1
Note
In the second test it is acceptable to print i = 2, j = 3.
还是万年吐槽,这英语没救了。题目都看不懂的我和瞎子已经没有什么区别了。
题意:
给你两个长度为n的字符串,你有一次机会,将一个字符串的两个字母互换位置。
(要求:要使这两个字符串的元素不同的最少)
如果能互换使得不同之处变少,则输出互换后有多少个不同的元素,
并且输出所交换的元素的位置,如不能则输出-1 -1。
这题是一个非常灵活的思维题,如果思路简单则可以复杂度很小的求出答案。
如果是复杂的思路那就tle了。
这题亮点是用一个二维数组tu[30][30]去维护这两个字符串不同点。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
char a[],b[];
int tu[][];
int main() {
while(scanf("%d%s%s",&n,a,b)!=EOF) {
int sum=;
memset(tu,,sizeof(tu));
for (int i= ; i<n ; i++ ) {
if (a[i]!=b[i]) {
tu[a[i]-'a'][b[i]-'a']=i+;
sum++;
}
}
int flag=;
if (flag) {
for (int i= ; i<n ; i++) {
if (a[i]!=b[i] && tu[b[i]-'a'][a[i]-'a']) {
printf("%d\n%d %d\n",sum-,tu[b[i]-'a'][a[i]-'a'],tu[a[i]-'a'][b[i]-'a']);
flag=;
break;
} }
}
if (flag) {
for (int i= ; i<n ; i++ ) {
if (a[i]!=b[i]) {
for (int j= ; j< ; j++) {
if (tu[b[i]-'a'][j]) {
printf("%d\n%d %d\n",sum-,tu[b[i]-'a'][j],i+);
flag=;
break;
}
}
if (flag==) break;
}
}
}
if (flag) printf("%d\n-1 -1\n",sum);
}
return ;
46}
Error Correct System CodeForces - 527B的更多相关文章
- CodeForces 527B Error Correct System
Error Correct System Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I6 ...
- 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 ...
- 【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. 分析: 用矩阵记录 ...
随机推荐
- BZOJ 1778: [Usaco2010 Hol]Dotp 驱逐猪猡 [高斯消元 概率DP]
1778: [Usaco2010 Hol]Dotp 驱逐猪猡 题意:一个炸弹从1出发p/q的概率爆炸,否则等概率走向相邻的点.求在每个点爆炸的概率 高斯消元求不爆炸到达每个点的概率,然后在一个点爆炸就 ...
- BZOJ 4555: [Tjoi2016&Heoi2016]求和 [FFT 组合计数 容斥原理]
4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...
- BZOJ 3895: 取石子[SG函数 搜索]
有N堆石子 ·从某堆石子中取走一个 ·合并任意两堆石子 不能操作的人输. 100%的数据满足T<=100, N<=50. ai<=1000 容易发现基础操作数$d=\sum a ...
- 洛谷3月月赛 R1 Step! ZERO to ONE
洛谷3月月赛 R1 Step! ZERO to ONE 普及组难度 290.25/310滚粗 t1 10分的日语翻译题....太难了不会... t2 真·普及组.略 注意长为1的情况 #include ...
- 夏令营提高班上午上机测试 Day 1 解题报告
Day 1的题难度上来说不算太高,但是T2和T3还是有一定的思维量的. 一个比较好的开始.虽然AK的人只有几个.. (懒得去翻result了..忘了当时拿了多少分了 (哦,前两天我们机房是没有成绩的, ...
- ubunt tftp服务器搭建
默认安装的Ubuntu系统没有包含TFTP的服务端和客户端,可以通过命令行来下载安装,步骤如下: (1)安装客户端. root@ www.linuxidc.com:~# apt-get install ...
- 金融&业务常识积累
前言 在项目中遇到很多名词,不太明白其含义.这些名词都是和金融领域紧密相关并且与项目的业务有着直接的联系.因此,决定通过搜集资料和归纳总结,对经后的工作产生一定的帮助. 常见的金融知识 PDL: Pa ...
- easyui datagrid 右边框被隐藏
问题前: 如下图: 解决思路: 待文档加载完成后再执行dategrid函数 $(function () { $("#tt").datagrid({ //....... }); }) ...
- github page博客里添加多说评论插件
本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 摘要: 由于现在我这个博客原来用的是DISQUS评论插件,那全是全球 ...
- http权威指南笔记
请求报文 响应报文GET /test/hi.txt HTTP/1.0 起始行 HTTP/1.0 200 OKAccept: text/* 首部 Content-type: text/plainAcce ...