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的更多相关文章
随机推荐
- (七)发送、接收SOAP消息(以HttpClient方式)(2)
一.为什么要用soap 原本我们使用web服务都是根据wsdl生成客户端(生成一堆java文件)然后再调用,本章节讲解如何用soap消息来替代这种方式. 二.SOAP消息格式 SOAP(简单对象访问协 ...
- java 框架-分布式文件管理系统1FastDFS
https://www.cnblogs.com/chiangchou/p/fastdfs.html
- gin框架实现一个简单的项目 ③
承接:gin框架封装自己的路由 ② 对于一个项目来说,需要将各个功能模块分开,也就是所谓的三层模型,这里介绍一下个人的做法: contorller主要负责路由 model主要负责程序输入输出的数据 s ...
- Java代理模式示例程序
Java代理模式示例程序 当然不是我想出来的,是我看的一个网上教程里的. 模拟的是一个对电脑公司的代理 真实类的接口: public interface SaleComputer { public S ...
- vue-cli搭建vue项目环境
该篇文章是继https://www.cnblogs.com/qing-5/p/11321585.html来写 1.打开终端,输入指令"npm install --global vue-cli ...
- stm32F1 DMA
DMA,全称是Direct Memory Access,中文意思为直接存储器访问 DMA可用于实现外设与存储器之间或者存储器与存储器之间数据传输的高效性 DMA请求映像 各通道的DMA1请求: 各通道 ...
- 从linux和ucos的比较中来看进程这个概念
这种问题就要和ucos结合起来嘛. 程序和进程: 程序:存放在磁盘上的一些列代码和数据的可执行映像,是一个静止的实体. 进程:是一个执行中的程序,它是动态的实体. linux进程的四要素: 1. 有一 ...
- 雨后清风U盘启动盘的五大用处及制作方法
如果有一个U盘可以帮助你安装系统,或者在你的电脑系统崩溃时帮助你修复系统,是不是很方便呢?雨后清风U盘启动盘就能帮你实现这样的效果.除此之外,雨后清风U盘启动盘还有另外一些用处.下面就来和大家分享一下 ...
- powerlink的Windows-DEMO生成笔记
资料准备: 1.Visual studio 2010 2.Cmake 3.Powerlink 2.7.1源码 具体下载请到相关页面去获取. 新版的powerlink分为两个部分: 1.协议栈 2.应用 ...
- ubuntu---记录.opencv多版本管理与切换
首先当然准备两个不同版本opencv (比如2..9和3.1.0) cmake-gui 设置 CMAKE_INSTALL_PREFIX 安装路径:/usr/local/opencv2 安装路径 :/u ...