codeforces533E
Correcting Mistakes
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 ndetermine 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 Tconsist of lowercase English letters. Word W also should consist of lowercase English letters.
Input
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 Tare distinct words.
Output
Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo.
Examples
7
reading
trading
1
5
sweet
sheep
0
3
toy
try
2
Note
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".
题目大意:给你两个字符串,这两个串都是在原串的基础上减去一个字母得到的,问你原串有几种可能性。
sol:首先把首尾两端相等的去掉,容易发现答案最大是2,
一开始睿智了,写了个XJB玩意,只判了两个位置,就会被这样的卡掉
如
aaab
baaa
于是就爆枚两种情况,一是S1的[L,R-1]等于S2的[L+1,R],还有一种就是类比一下
/*
题目大意:给你两个字符串,这两个串都是在原串的基础上减去一个字母得到的,问你原串有几种可能性。
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=; bool f=; char ch=' ';
while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
while(isdigit(ch)) {s=(s<<)+(s<<)+(ch^); ch=getchar();}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<) {putchar('-'); x=-x;}
if(x<) {putchar(x+''); return;}
write(x/); putchar((x%)+'');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,p[N],ans=,l,r,len;
char S[][N];
inline void Jud(int o)
{
int i;
for(i=l;i<r;i++)
{
if(S[o][i]!=S[o^][i+]) return;
}
ans++;
}
int main()
{
int i;
R(n);
scanf("%s%s",S[]+,S[]+);
l=; r=n;
while(S[][l]==S[][l]) l++;
while(S[][r]==S[][r]) r--;
if(l==n+&&r==)
{
Wl((n+)*); return ;
}
// cout<<l<<" "<<r<<endl;
len=r-l+;
Jud();
Jud();
Wl(ans);
return ;
}
/*
input
4
aaab
baaa
output
1
*/
codeforces533E的更多相关文章
随机推荐
- Asp.net core 学习笔记 ( ef core transaction scope & change level )
ef core 有 unit of work 的概念,当我们 save change 时会自动使用 transaction 确保更新的一致性. 隔离级别是默认的 read committed 不允许脏 ...
- HTML中关于动态创建的标签无法绑定js事件的解决方法:.on()方法的 [.selector]
在前端页面的时候,会经常遇到用JavaScript动态创建出来的Button按钮或其他标签无法使用点击事件的问题.如下代码,使用jquery在body中动态创建一个class为demo的Button按 ...
- SpringCloud"灰度部署"——动态刷新网关配置
通过Acutator和SpringCloudConfig完成"灰度部署"——动态刷新网关路由配置 先声明下,我这个可能是冒牌的灰度部署,技术有限,纯粹个人笔记分享. 前段时间接到了 ...
- 改写Unity DropDown 支持多次点击同一选项均回调
[很久前的一个Note,不知道现在的Unity Dropdown是否已经支持该特性] Unity UGUI是开源的: https://bitbucket.org/Unity-Technologies/ ...
- git remote 使用总结
使用场景:新建一个git仓储并与远程关联 1.初始化一个新的空的git仓储,并在仓储下做一些改动 mkdir gitDir cd gitDir/ git init touch file git sta ...
- nginx动静分离简单实例实现
什么是动静分离? Nginx 动静分离简单来说就是把动态和静态请求分开,不能理解成只是将动态页面和静态页面物理分离.严格意义上说应该是动态请求和静态请求分开,可以理解成使用 nginx 处理静态页面, ...
- Excel 教程二 单元格范围的使用
上一篇已经看了Excel这个软件的基本功能区,这一节我们来看一下我们经常使用的单元格范围. 一.首先我们看一下单元格,行和列 单元格指的是excel工作簿中的某一行某一列对应的具体位置,列指的是从上到 ...
- Ubuntu系统---系统驱动丢失、Kernel内核卸载、禁止更新
Ubuntu系统---系统驱动丢失.Kernel内核卸载.禁止更新 一早开机发现,ubuntu字体异常,字体很大,直接反应是驱动坏了.一查,确实丢失英伟达驱动,为什么呢?莫名的消失.想知道:1.英伟达 ...
- Kostya the Sculptor(贪心
这题本来 想二分.想了很久很久,解决不了排序和二分的冲突. 用贪心吧.. 题意: 给你n个长方形,让你找出2个或1个长方体,使得他们拼接成的长方体的内接球半径最大(这是要求最短边越大越好)( ...
- Linux文件系统之install(复制文件和设置文件属性)
install命令 install命令的作用是安装或升级软件或备份数据,它的使用权限是所有用户.install命令和cp命令类似,都可以将文件/目录拷贝到指定的地点.但是,install允许你控制目标 ...