【题目链接】:http://codeforces.com/contest/527/problem/B

【题意】



给你两个字符串;

允许你交换一个字符串的两个字符一次;

问你这两个字符串最少会有多少个位置上的字符不同

【题解】



考虑一次交换能够造成的结果

->不同的字符个数减少1

->不同的字符个数减少2

先考虑减少1

记录第一个字符串哪些字符和第二个字符串的不一样记录下来

然后扫描第二个字符串的每个字符,找到不同字符的位置,看看第二个字符串那个位置的字符有没有在第一个字符串里面出现过(刚才有记录的);

如果有的话,就说明能找到不同字符个数减少1的情况;

然后再考虑减少2的情况;

直接扫描一遍字符

如果s1[i]!=s2[i];

则a[s1[i]][s2[i]]=i

然后两层for循环i,j

如果a[i][j]&&a[j][i];

则交换a[i][j]和a[j][i]的字符,就能减少2了;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 256;
const int L = 2e5 + 100; int a[256][256],n,v[256],l=-1,r=-1,sub,ans = 0;
char s[L], t[L]; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(n);
scanf("%s", s + 1);
scanf("%s", t + 1);
rep1(i, 1, n)
if (s[i]!=t[i])
{
ans++;
v[s[i]] = i;
a[s[i]][t[i]] = i;
}
rep1(i,1,n)
if (t[i] != s[i])
{
if (v[t[i]])
{
l = v[t[i]], r = i;
sub = 1;
break;
}
}
for (char i = 'a';i <= 'z';i++)
for (char j = 'a';j <='z';j++)
if (a[i][j] && a[j][i])
{
l = a[i][j], r = a[j][i];
sub = 2;
break;
}
ans -= sub;
printf("%d\n", ans);
printf("%d %d\n", l, r);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 527B】Error Correct System的更多相关文章

  1. CodeForces 527B Error Correct System

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

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

  3. Error Correct System(模拟)

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

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. CF Error Correct System

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

  6. 【C/C++】Linux下system()函数引发的错误

    http://my.oschina.net/renhc/blog/54582 [C/C++]Linux下system()函数引发的错误 恋恋美食  恋恋美食 发布时间: 2012/04/21 11:3 ...

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

  8. 【63.73%】【codeforces 560A】Currency System in Geraldion

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 22C】 System Administrator

    [题目链接]:http://codeforces.com/problemset/problem/22/C [题意] 给你n个点; 要求你构造一个含m条边的无向图; 使得任意两点之间都联通; 同时,要求 ...

随机推荐

  1. git ldap

    https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md ldap : enabled : true host : 'ope ...

  2. bzoj3505 [Cqoi2014]数三角形——组合数+容斥

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3505 好题啊好题...好像还曾经出现在什么智力测试卷中来着...当时不会现在还是无法自己推出 ...

  3. jqxtree异步加载部门树

    整体思路 A.要想实现异步加载第一次加载的是一级部门 B.加载一级部门,如果有子部门,部门前面带+号,没有子部门,部门前面没有+号(+号也就是点击可以展开) C.在sql中实现如果有子部门默认都加载一 ...

  4. App设计师常用的10大网页和工具大盘点

    1.Adobe Photoshop 老牌的设计工具,不用解释 2.Adobe Illustrator 同上,不解释 3.Balsamiq Mockup 网址:http://balsamiq.com/ ...

  5. AirtestIDE详解(跨平台的UI自动化编辑器)

    Airtest 是网易出品的一款基于图像识别和poco控件识别的一款UI自动化测试工具. AirtestIDE 是一个跨平台.多端(Windows.web.android.ios.游戏)的UI自动化测 ...

  6. POJ 1584 计算几何

    思路: 求一遍凸包 用三角形面积(叉积求一下)/边长 求出来高,跟半径比一比 坑点:凸包上三点共线 //By SiriusRen #include <cmath> #include < ...

  7. 【BZOJ2944】[Poi2000]代码(卡特兰数)

    这题在网上找不到题解,硬写一下午终于写出来了-- 题目: BZOJ2944 分析: 首先明确: 比较两棵节点数相同的二叉树时,根节点是第一关键字,左子树是第二关键字,右子树是第三关键字: 然后我们分析 ...

  8. JS——筋斗云案例

    需求: 1.鼠标移动到哪里,云彩移动到哪里 2.鼠标离开,云彩回到原点 3.鼠标离开,云彩回到之前点击的地方 <!DOCTYPE html> <html lang="en& ...

  9. 常用的SSH注解标签

    常用的SSH注解标签 1.Spring的注解 关于配Bean用的        @Component        @Controller @Service @Repository        作用 ...

  10. C# 学习——静态(第四天)

    一.命名空间 类似于文件夹,而类就是文件夹中的文件: 作用:明确的指向我们所需要的类的 所在的位置: 统一命名空间下,类名不能重复. 二.类 概念:具有相同属性和功能的对象的抽象的集合. 三.静态与实 ...