题目大意:

给出两串n(1 ≤ n ≤ 200 000)个字母的字符串, 求出最多交换一对数, 使得不相同对数变少,求出不相同的对数以及交换的数的位置,若不需交换则输出-1,-1.

分析:

用矩阵记录两个串相同位置不同的字母,有三种情况,一种是交换后正好两个位置都对应相同,一种是交换后只有一个位置相同,还有就是交换也不能满足对应相同。

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#define maxn 200010
#define INF ~0u>>1
using namespace std;
int main()
{
int n,vist[][];
char a[maxn],b[maxn];
scanf("%d",&n);
scanf("%s",a);
scanf("%s",b);
memset(vist,,sizeof(vist));
int sum=;
for(int i=; i<n; i++)
{
if(a[i]!=b[i])
{
sum++;
vist[a[i]-'a'][b[i]-'a']=i+;
}
}
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(vist[i][j]&&vist[j][i])
{
printf("%d\n",sum-);
printf("%d %d\n",vist[i][j],vist[j][i]);
return ;
}
}
}
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(vist[i][j])
{
for(int k=;k<;k++)
{
if(vist[j][k])
{
printf("%d\n",sum-);
printf("%d %d",vist[i][j],vist[j][k]);
return ;
}
}
}
}
}
printf("%d\n",sum);
printf("-1 -1\n");
return ;
}

codeforce Error Correct System的更多相关文章

  1. CodeForces 527B Error Correct System

    Error Correct System Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I6 ...

  2. CF Error Correct System

    Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  3. Error Correct System(模拟)

     Error Correct System Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

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

  8. 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System

    题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...

  9. 【codeforces 527B】Error Correct System

    [题目链接]:http://codeforces.com/contest/527/problem/B [题意] 给你两个字符串; 允许你交换一个字符串的两个字符一次: 问你这两个字符串最少会有多少个位 ...

随机推荐

  1. 转载——PLSQL developer 连接不上64位Oracle 解决办法

    前两天刚下载了oracle 11g 64位的最新版本,安装成功之后,再安装PLSQL.结果使用PLSQL访问数据库时,死活连接不上.报错如下: Could not load "……\bin\ ...

  2. PowerMock 遇到的问题——2

    如果我们要测试的类继承另一个类,而且在构造方法中有super():那么怎么Mock那个super语句呢? 在PowerMock中有一个suppressConstructor方法,具体写法如下: Pow ...

  3. JSTL标准标签库

    有时使用EL和标准动作达不到目的,于是就引入定制标记. 对于JSP页面创作人员来说,定制标记使用起来比脚本要容易一些.不过对于JAVA程序员来说,简历定制标记处理器反而更困难.幸运的是,已经有了一个标 ...

  4. JS随鼠标坐标移动,显示浮动层内容

    在表单等项目中往往会遇到类似于“备注”.“说明”等100个字内的内容需要显示. 这些内容如果全部呈现开,会影响布局和美观,确又没有必要设计一个层或是一个页面. 那么,我们可以把这些内容放到浮动层中,鼠 ...

  5. KVO的内部实现原理

    kvo概述 kvo,全称Key-Value Observing,它提供了一种方法,当对象某个属性发生改变时,允许监听该属性值变化的对象可以接受到通知,然后通过kvo的方法响应一些操作. kvo实现原理 ...

  6. iOS开发之UITableView使用总结

    什么是UITableView 在众多移动应用中,能看到各式各样的表格数据 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView UITableView继承自UIScrollVie ...

  7. iOS 7 教程:定制iOS 7中的导航栏和状态栏

    目录(?)[-] iOS 7中默认的导航栏 设置导航栏的背景颜色 在导航栏中使用背景图片 定制返回按钮的颜 修改导航栏标题的字体 修改导航栏标题为图片 添加多个按钮 修改状态栏的风格 隐藏状态栏 总结 ...

  8. 03-树2 Tree Traversals Again

    这题是第二次做了,两次都不是独立完成,不过我发现我第一次参考的程序,也是参考老师(陈越)的范例做出来的.我对老师给的做了小幅修改,因为我不想有全局变量的的存在,所以我多传了三个参数进去.正序遍历每次都 ...

  9. JS原生回到顶部效果

    // 回到顶部 onload = function () { var oBtnTop = document.getElementById('toTop'); var timer = null; oBt ...

  10. c#多线程(UI线程,控件显示更新) Invoke和BeginInvoke 区别

    如果只是直接使用子线程访问UI控件,直接看内容三,如果想深入了解从内容一看起. 一.Control.Invoke和BeginInvoke方法的区别 先上总结: Control.Invoke 方法 (D ...