题目大意:

给出两串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. bzoj 2440: [中山市选2011]完全平方数

    #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #defin ...

  2. elasticsearch插件之一:bigdesk

    bigdesk是elasticsearch的一个集群监控工具,可以通过它来查看es集群的各种状态,如:cpu.内存使用情况,索引数据.搜索情况,http连接数等. 可用项目git地址:https:// ...

  3. 关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision

    char *ptr; //此后省略部分代码 ) //出错地方 那句话的意思是从 void* 到 int 的转换丢失精度,相信看到解释有些人就明白了, 此问题只会出现在X64位的Linux上,因为在64 ...

  4. web api同源策略

    1.重写JsonMediaTypeFormatter public class JsonpMediaTypeFormatter : JsonMediaTypeFormatter { private s ...

  5. dbcp连接池配置参数

    1.<!-- 数据源1 --> 2. <bean id="dataSource" 3. class="org.apache.commons.dbcp.B ...

  6. Codeforces 235C

    题目大意: 给定一个字符串,接下来再给n个字符串,求原字符串中含有多少个当前给定字符串的循环同构体的字符串的个数 以初始字符串构建后缀自动机,在自动机上前进的时候,比如当前需要匹配的字符串为aba,到 ...

  7. iOS闪烁效果工具 GlitchLabel

    GlitchLabel 用于给文字添加闪烁效果,效果图如下: 开发环境: iOS 7.0+ Swift 2.2 Xcode 7 示例代码:https://www.yuedecaifu.com 1 2 ...

  8. 对比学习UIKit和AppKit--入门级

    UIKit是用来开发iOS的应用的,AppKit是用来开发Mac应用的,在使用过程中他们很相似,可是又有很多不同之处,通过对比分析它们的几个核心对象,可以避免混淆. UIKit和AppKit都有一个A ...

  9. Android异步更新UI的四种方式

    Android异步更新UI的四种方式 2015-09-06 09:23 segmentfault 字号:T | T 大家都知道由于性能要求,android要求只能在UI线程中更新UI,要想在其他线程中 ...

  10. SQL server 与Oracle开发比较

    ●概念上区别 1.Oracle 是一种对象关系数据库管理系统(ORDBMS),而Sql server 只是关系型数据库管 理系统(RDBMS). 2.Oracle使用Internet文件系统,该系统基 ...