CodeForces 156A Message(暴力)
2 seconds
256 megabytes
standard input
standard output
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s.
String p is called a substring of string s if
you can read it starting from some position in the string s. For example, string "aba"
has six substrings: "a", "b", "a",
"ab", "ba", "aba".
Dr. Moriarty plans to take string s and cut out some substring from it, let's call it t.
Then he needs to change the substring t zero or more times. As a
result, he should obtain a fixed string u (which is the string that should be sent to Sherlock Holmes). One change is defined as making
one of the following actions:
- Insert one letter to any end of the string.
- Delete one letter from any end of the string.
- Change one letter into any other one.
Moriarty is very smart and after he chooses some substring t, he always makes the minimal number of changes to obtain u.
Help Moriarty choose the best substring t from all substrings of the string s.
The substring t should minimize the number of changes Moriarty should make to obtain the string u from
it.
The first line contains a non-empty string s, consisting of lowercase Latin letters. The second line contains a non-empty string u,
consisting of lowercase Latin letters. The lengths of both strings are in the range from 1 to 2000,
inclusive.
Print the only integer — the minimum number of changes that Dr. Moriarty has to make with the string that you choose.
aaaaa
aaa
0
abcabc
bcd
1
abcdef
klmnopq
7
暴力
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
string a;
string b;
int main()
{
cin>>a>>b; int len1=a.length();
int len2=b.length();
int ans=10000000;
int len=len2;
if(len1<len2)
{
swap(a,b);
swap(len1,len2);
} for(int i=1;i<len2;i++)
{
int num=0;
for(int k=i,j=0;k<len2&&j<len1;k++,j++)
{
if(b[k]==a[j])
num++;
}
ans=min(ans,len-num);
} for(int i=0;i<len1;i++)
{
int num=0;
for(int k=i,j=0;j<len2&&k<len1;j++,k++)
{
if(a[k]==b[j])
num++;
} ans=min(ans,len-num);
}
printf("%d\n",ans); return 0;
}
CodeForces 156A Message(暴力)的更多相关文章
- Karen and Game CodeForces - 816C (暴力+构造)
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as fo ...
- Chladni Figure CodeForces - 1162D (暴力,真香啊~)
Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circ ...
- Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)
The only difference between easy and hard versions is a number of elements in the array. You are giv ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- CodeForces - 589B(暴力)
题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...
- CodeForces - 589B(暴力+排序)
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
- Codeforces 479B. Towers 暴力
纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 129A-Cookies(暴力)
A. Cookies time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
随机推荐
- 从构建分布式秒杀系统聊聊验证码 给大家推荐8个SpringBoot精选项目
前言 为了拦截大部分请求,秒杀案例前端引入了验证码.淘宝上很多人吐槽,等输入完秒杀活动结束了,对,结束了...... 当然了,验证码的真正作用是,有效拦截刷单操作,让羊毛党空手而归. 验证码 那么到底 ...
- stl之hash_multiset
hash_multiset的元素不会被自己主动排序
- 用js来传参到父网页实现
今天搞了半天,用location.href提交参数到后台,结果php无法接收到参数,这让我找了半天,终于发现原因是本页被另外的主页引用了,最终发现问题出在提交js上,最终用parent.locatio ...
- js 时间对比
https://www.cnblogs.com/xiangsj/p/7977325.html http://www.jb51.net/article/45560.htm isOverdue (time ...
- spring boot下WebSocket消息推送(转)
原文地址:https://www.cnblogs.com/betterboyz/p/8669879.html WebSocket协议 WebSocket是一种在单个TCP连接上进行全双工通讯的协议.W ...
- 报错"the microsoft.jet.oledb.4.0 provider is not registered on the local machine"解决方案
报错提示:"the microsoft.jet.oledb.4.0 provider is not registered on the local machine" 错误起因:wi ...
- Struts2请求流程图
ServletContext中的内容: <s:property value="#attr['countries']['cn']"/> <br> Sessio ...
- vncviewer鼠标不同步问题
sh-4.1# virsh edit win7 把下面的参数: <input type='mouse' bus='ps2'/> 改成: <input type='tablet' bu ...
- python学习之locals()
locals() 返回一个字典对象.收集并返回局部变量.可以用在函数中,用来收集局部变量. >>> def f(): ... a = 'tom' ... print(locals() ...
- JS的类型转换,强制转换和隐式转换
JS的类型转换 1.强制转换 通过String(),Number(),Boolean()函数强制转换 var str=123; var str1='123'; console.log(typeof s ...