题目大意:

给出两串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. BroadcastReceiver的实例----基于Service的音乐播放器之一

    下面的程序开发了一个基于Service的音乐盒,程序的音乐将会由后台运行的Service组件负责播放,当后台的播放状态发生改变时,程序将会通过发送广播通知前台Activity更新界面:当用户单击前台A ...

  2. undefined reference to typeinfo - C++ error message

    undefined reference to typeinfo - C++ error message There are some compiler and loader error message ...

  3. 河流 tyvj1506

    题目大意: 给出一棵n个节点的有根树,一开始 树根 是一个控制点,现在要增加m个控制点,使得总费用最少. 给出每个节点的父节点以及到父节点的距离,还有这个节点的权值, 一个节点的费用 即它的权值 乘以 ...

  4. tab模块

    #!/usr/bin/env python # python startup file import sys import readline import rlcompleter import ate ...

  5. wp8.1 C#技巧: Data和ViewModel类编写

    在Data.cs namespace PicApp { [DataContract] class DataItem : PropertyChangeNotification { public even ...

  6. c# 多线程创建 ---简单

    Thread t = new Thread(new ParameterizedThreadStart(UploadCard)); t.IsBackground = false;//后台线程  前台线程 ...

  7. android listview getviewtypecount和getItemViewType

    package newdemo.jeno.listviewdemo; import android.app.Activity;import android.os.Bundle;import andro ...

  8. C++中两块内存重叠的string的copy方法

    如果两段内存重叠,用memcpy函数可能会导致行为未定义. 而memmove函数能够避免这种问题,下面是一种实现方式: #include <iostream> using namespac ...

  9. 每天学一点JAVA

    1.JAVA的反射机制 在运行时判断任意一个对象所属的类:在运行时构造任意一个类的对象:在运行时判断任意一个类所具有的成员变量和方法:在运行时调用任意一个对象的方法:生成动态代理. 2.关于ARRAY ...

  10. C#基础之程序集(一)

    一.什么是程序集? 程序集 其实就是bin目录的.exe 文件或者.dll文件. 二.原理 三.程序集分类 1.系统程序集 路径:C:\Windows\assembly 2.源代码生成的程序集 使用V ...