码迷,mamicode.com
首页 > 其他好文 > 详细

Error Correct System CodeForces - 527B

时间:2018-03-05 20:40:13      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:brief   ret   include   字母   lag   minimum   comparing   cst   replace   

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

Example

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.

 

 

  还是万年吐槽,这英语没救了。题目都看不懂的我和瞎子已经没有什么区别了。

  题意:

         给你两个长度为n的字符串,你有一次机会,将一个字符串的两个字母互换位置。

        (要求:要使这两个字符串的元素不同的最少)

        如果能互换使得不同之处变少,则输出互换后有多少个不同的元素,

        并且输出所交换的元素的位置,如不能则输出-1 -1。

 

这题是一个非常灵活的思维题,如果思路简单则可以复杂度很小的求出答案。

如果是复杂的思路那就tle了。

这题亮点是用一个二维数组tu[30][30]去维护这两个字符串不同点。

 

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int n;
 6 char a[200010],b[200010];
 7 int tu[30][30];
 8 int main() {
 9     while(scanf("%d%s%s",&n,a,b)!=EOF) {
10         int sum=0;
11         memset(tu,0,sizeof(tu));
12         for (int i=0 ; i<n ; i++ ) {
13             if (a[i]!=b[i]) {
14                 tu[a[i]-a][b[i]-a]=i+1;
15                 sum++;
16             }
17         }
18         int flag=1;
19         if (flag) {
20             for (int i=0 ; i<n ; i++) {
21                 if (a[i]!=b[i] && tu[b[i]-a][a[i]-a]) {
22                     printf("%d\n%d %d\n",sum-2,tu[b[i]-a][a[i]-a],tu[a[i]-a][b[i]-a]);
23                     flag=0;
24                     break;
25                 }
26 
27             }
28         }
29         if (flag) {
30             for (int i=0 ; i<n ; i++ ) {
31                 if (a[i]!=b[i]) {
32                     for (int j=0 ; j<30  ; j++) {
33                         if (tu[b[i]-a][j]) {
34                             printf("%d\n%d %d\n",sum-1,tu[b[i]-a][j],i+1);
35                             flag=0;
36                             break;
37                         }
38                     }
39                     if (flag==0) break;
40                 }
41             }
42         }
43         if (flag) printf("%d\n-1 -1\n",sum);
44     }
45     return 0;
46}

 

 

Error Correct System CodeForces - 527B

标签:brief   ret   include   字母   lag   minimum   comparing   cst   replace   

原文地址:https://www.cnblogs.com/qldabiaoge/p/8510868.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!