#422(div2)B. Crossword solving

题意:给出2个字符串,A,B,A长度严格小于B长度,问改动A多少个字符,能成为B的子串,求最少改动

思路:暴力,2层FOR循环,可用set来存储已B的第i个字符为首需要改动的位置

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 set<int >a[1002];
 5 int main(){
 6     int n,m;
 7     cin>>n>>m;
 8    string s1,s2;
 9    cin>>s1>>s2;
10    int l,sum;
11    int y;
12    int Max=1e9;
13    for(int i=0;i<=m-n;i++){
14         l=i;sum=0;
15
16         for(int j=0;j<s1.size();j++){
17             if(s1[j]!=s2[l++]) {
18                     sum++;
19
20                     a[i].insert(j+1);
21             }
22         }
23
24         if(sum<Max){
25             Max=sum;y=i;
26         }
27    }
28    cout<<Max<<endl;
29    for(set<int >::iterator it=a[y].begin();it!=a[y].end();it++){
30         printf("%d ",*it);
31    }
32    cout<<endl;
33 }
时间: 2024-07-31 18:15:31

#422(div2)B. Crossword solving的相关文章

codeforces round 422 div2 补题 CF 822 A-F

A I'm bored with life 水题 #include<bits/stdc++.h> using namespace std; typedef long long int LL; const LL N=1,M=1,MOD=1; int main() {//freopen("t.txt","r",stdin); ios::sync_with_stdio(false); LL a,b; scanf("%I64d%I64d",&

B - Crossword solving

Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the

#422(div2)C. Hacker, pack your bags!

题意:给出n个区间和X,每个区间有左右边界和价值,li,ri,x.然后问从这n个区间找出2个不重合的区间,他们的区间长度和为x,并且价值最小 思路:我们可以预处理出每个长度所包含的区间,然后可以保存每个区间L的位置,和R的位置,那么在某个位置(某个L),前面的都是无重合,在判断下X-当前区间的长度 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const long long INF=1e18

Codeforces Round #422 B

Crossword solving 题意:给2个字符串s1,s2,求至少改变s2的多少个字符,才能使s2中包含s1,并输出改变的位置 思路:暴力枚举以每一个位置为开始,和s2匹配,求答案 AC代码: #include<bits/stdc++.h> #include "iostream" #include "string.h" #include "stack" #include "queue" #include &q

Codeforces Round #422 (Div. 2) A-C

A. I'm bored with life 水题 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> #include <map> using name

ACM团队周赛题解(3)

940和822两套div.2 老规矩 #define MAXN 1000000+5#define MOD 1000000007#define PI (acos(-1.0))#define EPS 1e-6#define MMT(s,a) memset(s, a, sizeof s)#define GO(i,a,b) for(int i = (a); i < (b); ++i)#define GOE(i,a,b) for(int i = (a); i <= (b); ++i)#define OG

JsSIP.UA.JsSIP 总是返回错误:422 Session Interval Too Small

在JsSIP 中 JsSIP.UA.call 总是 返回错误:422 Session Interval Too Small 关于错详情在这篇文章中解释的比较详尽:http://www.cnblogs.com/yoyotl/p/4980817.html 但是没有JsSIP的解决方法 具体的解决方法如下: JsSIP.js中的搜索 SESSION_EXPIRES: 把这个参数改大,  大于120就行了, (要是还不行,就继续加大吧^.^) SESSION_EXPIRES: 90 加大: SESSIO

cf386(div2)大一狗ACM之路

#cf386(div2)总结#前两题很顺利的做了出来, c题扔了, D题wrong了5发才A掉.A题签到题, 但是想多了, 代码写的有点长了. 找被整除最小值*7.B题 读题读了一会, 读完了就有思路了, 1A. 字符串问题, 从后往前两个两个的放到新的字符串里, 一个从最左, 一个从最右, 模拟指针扫着放, 最后特判会不会扫到一起.C题跳了没看, 最后做完了D题回来看了一眼没什么思路 日后再说.D题, 恩.. 两个多小时都用在这题上面了, 20分钟的时候做完了B之后就一直再啃D题, 暴力判断啊

TTL,COMS,USB,232,422,485电平之详细介绍及使用

如有错误敬请指导! 今天来详细介绍一下TTL,COMS,USB,232,422,485电平,以及之间的转换问题. 有些地方的引脚图可能不是规范的,具体引脚以自己的模块资料为主,这篇文章着重介绍使用... 先介绍各个电平 TTL电平------我们使用的51单片机,5V供电的那种,+5V等价于逻辑“1”,0V等价于逻辑“0”,“TTL电平”最常用于有关电专业,如:电路.数字电路.微机原理与接口技术.单片机等课程中都有所涉及.在数字电路中只有两种电平(高和低)高电平+5V.低电平0V. COMS电平