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 ...
随机推荐
- mysql init_connect
init_connect 服务器为每个连接的客户端执行的字符串.字符串由一个或多个SQL语句组成.要想指定多个语句,用分号间隔开.例如,每个客户端开始时默认启用autocommit模式.没有全局服务器 ...
- Cocos2d-x 3.1.1 Lua演示样例 ActionsProgressTest(进度条)
Cocos2d-x 3.1.1 Lua演示样例 ActionsProgressTest(进度条) 本篇博客介绍Cocos2d-x中的进度条动画,进度条涉及以下几个重要的类和方法,笔者来给大家具体解说一 ...
- Python学习之read()方法
read([size [,chars [,firstline]]]) 含义: 从文本流(io.TextIOWrapper)中解码数据并返回字符串对象.
- 玩黑客学校CTF
关卡很简单就不细说.不懂的百度 第一关: 源码: 解密得出为JO 第二关: 很明白,表单问题. </script> <div style = "text-align: ce ...
- 内核补丁 patch
https://www.kernel.org/diff/diffview.cgi?file=/pub/linux/kernel/v3.x/patch-3.18.12.xz
- position: absolute、relative的问题
设置此属性值为 absolute 会将对象拖离出正常的文档流绝对定位而不考虑它周围内容的布局.假如其他具有不同 z-index 属性的对象已经占据了给定的位置,他们之间不会相互影响,而会在同一位置层叠 ...
- City Destruction Kattis - city dp
/** 题目:City Destruction Kattis - city 链接:https://vjudge.net/problem/Kattis-city 题意:有n个怪兽,排成一行.每个怪兽有一 ...
- 分析kube-proxy的iptables规则
NodePort service 创建一个mysql的NodePort服务,对应两个pod实例,rc和service的配置如下: 1.rc配置 apiVersion: v1 kind: Replica ...
- Could not resolve dependencies for project
最近项目上使用的是idea ide的多模块话,需要模块之间的依赖,比如说系统管理模块依赖授权模块进行认证和授权,而认证授权模块需要依赖系统管理模块进行,然后,我就开始相互依赖,然后出现这样的问题: “ ...
- datagrid后台分页js
$(function () { gridbind(); bindData(); }); //表格绑定function gridbind() { $('#dg').datagrid({ title: ' ...