VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串
题目链接:http://codeforces.com/contest/533/problem/E
2 seconds
256 megabytes
standard input
standard output
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics.
Polycarp needed to write a code that could, given two words, check whether they could have been obtained from the same word as a result of typos. Polycarpus suggested that the most common typo is skipping exactly one letter as you type a word.
Implement a program that can, given two distinct words S and T of
the same length n determine how many words W of
length n + 1 are there with such property that you can transform W into
both S, and T by
deleting exactly one character. Words S and T consist
of lowercase English letters. Word W also should consist of lowercase English letters.
The first line contains integer n (1 ≤ n ≤ 100 000)
— the length of words S and T.
The second line contains word S.
The third line contains word T.
Words S and T consist
of lowercase English letters. It is guaranteed that S and T are
distinct words.
Print a single integer — the number of distinct words W that can be transformed to S and T due
to a typo.
7
reading
trading
1
5
sweet
sheep
0
3
toy
try
2
In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold).
In the second sample test the two given words couldn't be obtained from the same word by removing one letter.
In the third sample test the two given words could be obtained from either word "tory" or word "troy".
题解:
假设字符串为S和T,可知答案最大只能为2.
1.跳过左右两端相同的部分,直到遇到相等的字符为止。
2.只有两种情况:S的左边和T的右边为公共部分、S的右边和T的左边为公共部分。
代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = 1e5+; int n;
char S[maxn], T[maxn]; int f(char *s1, char *s2, int i, int j)
{
while(i<j && s1[i]==s2[i+])
i++;
return i==j;
} int main()
{
scanf("%d%s%s",&n, S+,T+); int i = , j = n;
while(i<=n && S[i]==T[i]) i++;
while(j>= && S[j]==T[j]) j--; int ans = ;
ans += f(S, T, i, j);
ans += f(T, S, i, j);
cout<<ans<<endl;
}
VK Cup 2015 - Round 2 E. Correcting Mistakes —— 字符串的更多相关文章
- Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题
E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线
题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可 先考虑第一种情况, 第二种类似,sw ...
- VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp
题目链接: http://codeforces.com/problemset/problem/533/B B. Work Group time limit per test2 secondsmemor ...
- VK Cup 2015 - Round 1 E. Rooks and Rectangles 线段树 定点修改,区间最小值
E. Rooks and Rectangles Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemse ...
- VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)
VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) 代码 VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) A ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!
Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...
- VK Cup 2015 - Qualification Round 1 D. Closest Equals 离线+线段树
题目链接: http://codeforces.com/problemset/problem/522/D D. Closest Equals time limit per test3 secondsm ...
- codeforces VK Cup 2015 - Qualification Round 1 B. Photo to Remember 水题
B. Photo to Remember Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/522/ ...
随机推荐
- JVM 常量池
最近正好在研究这个问题,题主问题本身是有问题的,在JDK7中HotSpot的常量池是放在Java Heap中,并非题目中的native memory中.在JDK6中是放在Perm Space.题主可以 ...
- ListView 在设备切换横竖屏时保存状态
比如listview在设备切换横竖屏时,仍然需要保证position, activity - > onSaveInstanceState - > restoreInstanceState ...
- Uoj #350. 新年的XOR
前缀异或和是可以讨论的,非常naive,然后这就是个水题了23333 #include<bits/stdc++.h> #define ll long long using namespac ...
- restful的认识和用法
目录 一.restful的认识 1.基本概念 2.规范和约束 3.使用标准的状态码 二.具体使用 1.简单概括 2.根据id查询一个员工 3.查询所有员工 4.保存一个员工 5.根据id修改员工 6. ...
- android 打开软键盘
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...
- Maven引入本地Jar包并打包进War包中
1.概述 在平时的开发中,有一些Jar包因为种种原因,在Maven的中央仓库中没有收录,所以就要使用本地引入的方式加入进来. 2. 拷贝至项目根目录 项目根目录即pom.xml文件所在的同级目录,可以 ...
- sql语言复习2
一.查询 select 字段列表 from 表名列表 [where 条件表达式][group by 字段列表[having 条件表达式]] [order by 字段列表[asc|desc]] 含义:在 ...
- 10934 - Dropping water balloons(DP)
这道题的思路非常难想. 问你须要的最少实验次数,这是非常难求解的.并且我们知道的条件仅仅有三个.k.n.实验次数 . 所以我们最好还是改变思路,转而求最高所能确定的楼层数 . 那么用d[i][j]表 ...
- python(24)- 面向对象进阶
面向对象基础知识: 1.面向对象是一种编程方式,此编程方式的实现是基于对类和对象的使用: 2.类是一个模板,模板中包装了多个‘函数’供使用(可以将多函数中公用的变量封装到对象中): 3.对象,根据模板 ...
- python(34)- 模块与包练习
创建如下目录结构 keystone/ ├── __init__.py └── auth ├── __init__.py └── plugins └── core.py ...