【codeforces 527B】Error Correct System
【题目链接】: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的更多相关文章
- CodeForces 527B Error Correct System
Error Correct System Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I6 ...
- 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 ...
- Error Correct System(模拟)
Error Correct System Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- CF Error Correct System
Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 【C/C++】Linux下system()函数引发的错误
http://my.oschina.net/renhc/blog/54582 [C/C++]Linux下system()函数引发的错误 恋恋美食 恋恋美食 发布时间: 2012/04/21 11:3 ...
- 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 ...
- 【63.73%】【codeforces 560A】Currency System in Geraldion
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 22C】 System Administrator
[题目链接]:http://codeforces.com/problemset/problem/22/C [题意] 给你n个点; 要求你构造一个含m条边的无向图; 使得任意两点之间都联通; 同时,要求 ...
随机推荐
- Akka源码分析-Remote-ActorSystem
前面的文章都是基于local模式分析的,现在我们简要分析一下在remote模式下,ActorSystem的创建过程. final val ProviderClass: String = setup.g ...
- akka设计模式系列-慎用ask
慎用ask应该是Akka设计的一个准则,很多时候我们应该禁用ask.之所以单独把ask拎出来作为一篇博文,主要是akka的初学者往往对ask的使用比较疑惑. "Using ask will ...
- 推荐给Web前端开发人员的一些书籍(从基础到架构阶段)
有很多人问我说作为一个前端开发人员都需要看一些什么书籍,尤其是刚入门的新手,今天我整理了一下推荐给大家,大佬绕过. HTML+CSS+JavaScript 网页设计 从入门到精通 作为一个前端新手,强 ...
- assistant: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by
[oracle@oracledb button]$ assistantassistant: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' no ...
- 【学习笔记】OI玄学道—代码坑点
[学习笔记]\(OI\) 玄学道-代码坑点 [目录] [逻辑运算符的短路运算] [\(cmath\)里的贝塞尔函数] 一:[逻辑运算符的短路运算] [运算规则] && 和 || 属于逻 ...
- 【洛谷4396/BZOJ3236】[AHOI2013]作业(莫队+分块/树状数组/线段树)
题目: 洛谷4396 BZOJ3236(权限) 这题似乎BZOJ上数据强一些? 分析: 这题真的是--一言难尽 发现题面里没说权值的范围,怕出锅就写了离散化.后来经过面向数据编程(以及膜神犇代码)知道 ...
- (转)Spring AOP的底层实现技术
AOP概述 软件的编程语言最终的目的就是用更自然更灵活的方式模拟世界,从原始机器语言到过程语言再到面向对象的语言,我们看到编程语言在一步步用更自然.更强大的方式描述软件.AOP是软件开发思想的一个飞跃 ...
- JS——缓慢动画封装
在知道如何获取内嵌式和外链式的标签属性值之后,我们再次封装缓慢动画: 单个属性 <!DOCTYPE html> <html> <head lang="en&qu ...
- CSS——text-indent
在h1标签里套入a标签并写上文字,有利于seo,但是文字如何隐藏呢?一般都是a标签变成内联块并首行缩进为负值. <!DOCTYPE html> <html lang="en ...
- [Windows Server 2003] IIS自带FTP安装及配置方法
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:IIS6.0自 ...