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 ...
随机推荐
- android 签名、混淆打包
1.android 签名 使用eclipse导出带签名的apk,最简单的方式. 最后一步finish ,就能导出一个xxx.keystore的文件了. 下次再发布新版本的时候,使用这个生成的签名继续使 ...
- 点滴积累【JS】---JS小功能(JS实现匀速运动)
效果: 思路: 利用setInerval()计时器,进行运动.然后关键的一点是在最后停止的时候给它一个填充缝隙的判断. 代码: <head runat="server"> ...
- 在ubuntu上使用Virtual-Box安装Mininet
使用Virtual-Box安装Mininet看上去简单,但其中也暗藏许多坑.我自己装了多次Mininet,但每次都有缺陷: mininet访问不了网络 用宿主机访问不了mininet虚拟机 最后,终于 ...
- socket failed:EACCES(Permission denied)
1. 权限问题 安卓端写的TCP协议软件报错原因是建立的套接字没有限权对外连接. 在AndroidManifest.xml中,加上这一句话,取得权限. <uses-permission andr ...
- SVN提交项目时版本冲突解决方案
版本冲突原因: 假设A.B两个用户都在版本号为7的时候,更新了index.jsp这个文件,A用户在修改完成之后提交index.jsp到服务器,这个时候提交成功,这个时候index.jsp文件的版本号已 ...
- 解决错误: ios property has a previous declaration
今天维护一个项目的时候,我新添加了一个库,运行的时候报错了: ios property has a previous declaration 上网查了一下没有找到思路,不过根据提示自己试了一下,原来这 ...
- request.setCharacterEncoding()对通过method="GET"输入的参数无效
通过GET提交参数有2种 1.浏览器地址栏输入URL?parameter1=value1¶meter2=value2 2.<form method="get" ...
- jquery ui 与 easy ui同时引入 展示效果冲突的问题
jquery ui 由于在定位控件的时候跟easy UI 控件名相同,同时引入会导致冲突 如果需要两个都存在,可以去jquery ui下载定制版ui 脚本文件
- 如何将自己的网站分享到QQ空间,微信,微博等等。
逛一些网站的时候经常会看到右侧挂个分享栏,让用户把自己的站分享到qq空间,微信等等,所以自己也研究了下,把他加到了自己的网站上,喜欢的可以先看看效果:去转盘网,不多说了,直接上代码: window._ ...
- 【★】深入BGP原理和思想【第…
前言:学思科技术我想说,浅尝辄止,不是天才千万别深钻.和我研究高等数学一样,越深入就会发现越多的问题与不合理之处.尤其对于IT界,算法的最终解释权还是掌握在老外手中,所以对于有些细节,我们" ...