codeforce Error Correct System
题目大意:
给出两串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的更多相关文章
- CodeForces 527B Error Correct System
Error Correct System Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I6 ...
- CF Error Correct System
Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Error Correct System(模拟)
Error Correct System Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System
题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...
- 【codeforces 527B】Error Correct System
[题目链接]:http://codeforces.com/contest/527/problem/B [题意] 给你两个字符串; 允许你交换一个字符串的两个字符一次: 问你这两个字符串最少会有多少个位 ...
随机推荐
- 统计sql语句执行效率
--统计sql语句执行效率SELECT (total_elapsed_time / execution_count)/1000 N'平均时间ms' ,total_elapsed_time/1000 N ...
- iOS https(SSL/TLS)数据捕获
要捕获iPhone上的appstore的数据还真的没那么容易,以前介绍的那些使用代理手工导入证书的方法已经完全失效了,结果就是安装证书之后再打开appstore也无法正常的建立连接.按照我的分析其实是 ...
- .className = "highlight";.setAttribute("class", "highlight");
document.getElementById("top").innerHTML = newHTML; document.getElementById("contact& ...
- WebBrowers & HtmlViewers collection
WebBrowers & HtmlViewers collection 浏览: 加入我的收藏 楼主: THtmlViewerhttps://github.com/BerndGabriel/Ht ...
- 戴文的Linux内核专题:05配置内核(1)
转自Linux中国 现在我们已经了解了内核,现在我们可以进入主要工作:配置并编译内核代码.配置内核代码并不会花费太长时间.配置工具会询问许多问题并且允许开发者配置内核的每个方面.如果你有不确定的问题或 ...
- [转]powerDesigner生成excel版本的数据库文件
powerDesigner生成excel版本的数据库文件 出处:http://ray-allen.iteye.com/blog/1893347 脚本 excel 今天收到一个需求,要把数据库设计给一 ...
- 最大子段和-Program A
最大子段和 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description G ...
- Android安全之WebViewUXSS漏洞
Android安全 WebView UXSS app开发 漏洞分析 移动安全 0X01 前言 XSS是我们比较熟悉的一种攻击方式,包括存储型XSS.反射型XSS.DOM XSS等,但UXSS(通用型X ...
- 关于SharePoint REST中的授权的研究
博客地址:http://blog.csdn.net/FoxDave 当我们开发SharePoint APP需要调用REST服务时,可以使用OAuth完成授权,也可以使用跨域库.以下是微软专家的一段注解 ...
- python几大排序算法
1.插入排序 原理:有数列[k1,k2,k3...],假设k1是排好序的,插入k2,排序完成,然后再插入k3,以此类推 def insert_sort(arr): for i in range(1,l ...