字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System
/*
无算法
三种可能:1.交换一对后正好都相同,此时-2
2.上面的情况不可能,交换一对后只有一个相同,此时-1
3.以上都不符合,则不交换,-1 -1 */
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <set>
using namespace std; const int MAXN = 2e5 + ;
const int INF = 0x3f3f3f3f; char s[MAXN], t[MAXN];
int p[][]; bool check1(int cnt)
{
for (int i=; i<; ++i)
{
for (int j=; j<; ++j)
{
if (p[i][j] && p[j][i])
{
printf ("%d\n", cnt-);
printf ("%d %d\n", p[i][j], p[j][i]);
return true;
}
}
} return false;
} bool check2(int cnt)
{
for (int i=; i<; ++i)
{
for (int j=; j<; ++j)
{
if (p[i][j])
{
for (int k=; k<; ++k)
{
if (p[k][i])
{
printf ("%d\n", cnt-);
printf ("%d %d\n", p[i][j], p[k][i]);
return true;
}
}
}
}
} return false;
} void work(int n)
{
int cnt = ;
for (int i=; i<n; ++i)
{
if (s[i] != t[i])
{
p[s[i]-'a'][t[i]-'a'] = i + ;
cnt++;
}
}
if (check1 (cnt)) return ;
if (check2 (cnt)) return ; printf ("%d\n", cnt);
puts ("-1 -1");
} int main(void)
{
//freopen ("B.in", "r", stdin); int n;
while (~scanf ("%d", &n))
{
memset (p, , sizeof (p));
scanf ("%s", &s);
scanf ("%s", &t); work (n);
} return ;
}
字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System的更多相关文章
- 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 ...
- Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路
Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xx ...
- 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax
题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...
- 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...
- 字符串处理 Codeforces Round #285 (Div. 2) B. Misha and Changing Handles
题目传送门 /* 题意:给出一系列名字变化,问最后初始的名字变成了什么 字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,pos[m] 数组记录初始位置 在每一次更新时都把初始pos加上 ...
- Codeforces Round #296 (Div. 1) E. Triangles 3000
http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...
- 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) A. Playing with Paper
题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...
- 贪心/字符串处理 Codeforces Round #291 (Div. 2) A. Chewbaсca and Number
题目传送门 /* WA了好几次,除了第一次不知道string不用'\0'外 都是欠考虑造成的 */ #include <cstdio> #include <cmath> #in ...
随机推荐
- [Effective JavaScript 笔记]第2章:变量作用域--个人总结
前言 第二章主要讲解各种变量作用域,通过这章的学习,接触到了很多之前没有接触过的东西,比如不经常用到的eval,命名函数表达式,with语句块等,下面是一个列表,我对各节的一点点个人总结,很多都是自己 ...
- How To Install Linux, Nginx, MySQL, PHP (LEMP) Stack on Debian 7
https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on- ...
- Stanford机器学习---第四讲. 神经网络的表示 Neural Networks representation
原文 http://blog.csdn.net/abcjennifer/article/details/7749309 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...
- Firefox渗透测试黑客插件集
前天看S哥用Firefox的hackbar进行手动注入进行渗透,觉得直接运用浏览器的插件进行渗透测试有很多优点,既可以直接在前端进行注入等操作,也可以省却了寻找各种工具的麻烦.前端还是最直接的!于是这 ...
- Minimum Depth of Binary Tree
二叉树的最小深度 采用递归的方式求左右结点的高度,注意判断一个结点是否是叶子结点(左右子树都不存大). int minDepth(TreeNode *root) { return minDepth(r ...
- HDU1711
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- poj2485 Highways
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- MySQL 如何只导出 指定的表 的表结构和数据 ( 转 )
MySQL 如何只导出 指定的表 的表结构和数据 ( 转 ) 2011-01-04 15:03:33 分类: MySQL MySQL 如何只导出 指定的表 的表结构和数据 导出更个库的表结构如下:my ...
- 【Python】Django 如何直接返回404 被 curl,wget 捕获到
代码示例: from django.http import Http404, HttpResponseNotFound #raise Http404(filename) return HttpResp ...
- ubuntu下设置Android手机驱动
如果下面的文章不好使,建议读一这个文章:http://forum.xda-developers.com/xperia-u/general/howto-usb-connection-to-ubuntu- ...