题目大意:

给出两串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. TCP协议基础

    IP协议是Internet上使用的一个关键协议,它的全称是Internet  Protocol,即Internet协议,通常简称IP协议.通过使用IP协议,使Internet·成为一个允许连接不同类型 ...

  2. [示例]NSDictionary编程题-字典的排序应用(iOS5班)

    代码? #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepo ...

  3. Genymotion常见问题整合与解决方案

    常见问题1:Genymotion在开启模拟器时卡在了starting virtual device(注意只有tarting virtual device窗口,没有模拟器的黑屏窗口)    原因:Vir ...

  4. bzoj 2744: [HEOI2012]朋友圈

    #include<cstdio> #include<iostream> #define M 3010 using namespace std; ],u[M*M>>] ...

  5. 周游加拿大(dp好题)

    你赢得了一场航空公司举办的比赛,奖品是一张加拿大环游机票.旅行在这家航空公司开放的最西边的城市开始,然后一直自西向东旅行,直到你到达最东边的城市,再由东向西返回,直到你回到开始的城市.每个城市只能访问 ...

  6. SQL Server 自定义字符串分割函数

    一.按指定符号分割字符串,返回分割后的元素个数,方法很简单,就是看字符串中存在多少个分隔符号,然后再加一,就是要求的结果(标量值函数)   create function Func_StrArrayL ...

  7. C++封装库

    1.新建项目 -> Win32项目    选择DLL , 勾选 空项目 , 点击完成. 2.本例程,使用一个CPP文件 , 及一个头文件. 其中头文件包含函数声明,CPP文件实现函数声明. 3. ...

  8. java的动态绑定和静态绑定

    首先是方法的参数是父类对象,传入子类对象是否可行然后引出Parent p = new Children();这句代码不是很理解,google的过程中引出向上转型要理解向上转型又引出了动态绑定从动态绑定 ...

  9. iOS:图片拉伸不变形技巧

    方法: 假设图片为60*24 CGFloat top = image.height*0.5-1; // 顶端盖高度 CGFloat bottom = top ; // 底端盖高度 CGFloat le ...

  10. mybatis分页插件PageHelper的使用(转)

    Mybatis 的分页插件PageHelper-4.1.1的使用 Mybatis 的分页插件 PageHelper 项目地址:http://git.oschina.net/free/Mybatis_P ...