codeforces C. Double-ended Strings

Codeforces Round #710 (Div. 3) Codeforces Round #710 Div. 3A. Strange Table代码B. Partial Replacement思路:代码 A. Strange Table 题目链接 代码 #include<bits/stdc++.h> using namespace std; const int N=1e5+10; int T; int a[N]; #define int long long // typedef long long ll; signed main() { i 阅读详情

C. Double-ended Strings

You are given the strings a and b, consisting of lowercase Latin letters. You can do any number of the following operations in any order:

if |a|>0 (the length of the string a is greater than zero), delete the first character of the string a, that is, replace a with a2a3…an;
if |a|>0, delete the last character of the string a, that is, replace a with a1a2…an−1;
if |b|>0 (the length of the string b is greater than zero), delete the first character of the string b, that is, replace b with b2b3…bn;
if |b|>0, delete the last character of the string b, that is, replace b with b1b2…bn−1.
Note that after each of the operations, the string a or b may become empty.

For example, if a=“hello” and b=“icpc”, then you can apply the following sequence of operations:

delete the first character of the string a ⇒ a=“ello” and b=“icpc”;
delete the first character of the string b ⇒ a=“ello” and b=“cpc”;
delete the first character of the string b ⇒ a=“ello” and b=“pc”;
delete the last character of the string a ⇒ a=“ell” and b=“pc”;
delete the last character of the string b ⇒ a=“ell” and b=“p”.
For the given strings a and b, find the minimum number of operations for which you can make the strings a and b equal. Note that empty strings are also equal.

Input
The first line contains a single integer t (1≤t≤100). Then t test cases follow.

The first line of each test case contains the string a (1≤|a|≤20), consisting of lowercase Latin letters.

The second line of each test case contains the string b (1≤|b|≤20), consisting of lowercase Latin letters.

Output
For each test case, output the minimum number of operations that can make the strings a and b equal.
Example

Input
5
a
a
abcd
bc
hello
codeforces
hello
helo
dhjakjsnasjhfksafasd
adjsnasjhfksvdafdser

Output
0
2
13
3
20

题意
通过删减两个字符串的首或尾字符,使两个字符串相等。
题解
有题意可以得到,只删除首尾字符使两个字符串相等,那么我们可以等价于找到两个字符串中最长的公共子字符串。
这个时候我们可以通过一个二维的数组来找到这个最长子字符串
标记相同的字符所在的二维坐标为一,
比如
abcde 和bcdea
a b c d e
b 0 1 0 0 0
c 0 0 1 0 0
d 0 0 0 1 0
e 0 0 0 0 1
a 1 0 0 0 0
既然这样,那我们是不是可以通过将将要标记的字符标记为上一个标记的字符加一来确定一个字符串的长度,也就变为了
a b c d e
b 0 1 0 0 0
c 0 0 2 0 0
d 0 0 0 3 0
e 0 0 0 0 4
a 1 0 0 0 0
由此我们就可以得到最大的子字符串的长度,再用两个字符串的长度减去这给最大子字符串的两倍,就得到了结果。

#include<iostream>
#include<vector>
#include<string> 
#include<algorithm>
#include<cmath>
#include<memory>
#include<map>
#include<iomanip>
using namespace std;
#define ll long long
int c[25][25] = { 0 };
ll st(string a, string b) {
	ll max = 0;
	for (int i = 0; i < a.size(); i++) {
		for (int j = 0; j < b.size(); j++) {
			if (a[i] == b[j]) {
				if (i > 0 && j > 0) {
					c[i][j] = c[i - 1][j - 1] + 1;
				}
				else c[i][j] = 1;
			}
			if (c[i][j] > max)max = c[i][j];
		}
	}
	return max;
}
int main() {
	int t;
	cin >> t;
	while (t--) {
		string s;
		string str;
		cin >> s >> str;
		ll sum = st(s, str);
		for (int i = 0; i < s.size(); i++) {
			for (int j = 0; j < str.size(); j++) {
				c[i][j] = 0;
			}
		}
		cout << (s.size() + str.size() - 2 * sum) << endl;
	}
	return 0;
}
Ardupilot环境搭建 Ardpilot介绍:ArduPilot通过多种传感器的数据(GPS、加速度计、气压计、磁场计)等来估计飞行器的姿态,从而使飞行器能够保持稳定。 阅读详情

相关推荐

Viobot使用教程总贴

使用教程总贴

weixin_66666206的博客 1409

【思维】ABC

题目描述 You are given a string s consisting of A, B and C.Snuke wants to perform the following operation on s as many times as possible:Choose a contiguous substring of s that reads ABC and replace...

weixin_30609287的博客 206

医疗领域BGE-M3模型微调全流程:从数据准备到效果评估

本文详细介绍了医疗领域BGE-M3模型的微调全流程,从数据准备到效果评估。通过医疗数据微调,BGE-M3模型在临床问答、病历检索等场景中表现显著提升,能够准确理解医学术语之间的细微差别。文章还提供了实战练习代码和效果评估指标,帮助开发者快速掌握医疗文本嵌入模型的应用技巧。

weixin_29098367的博客 282

C. Double-ended Strings

C. Double-ended Strings 题面: You are given the strings a and b, consisting of lowercase Latin letters. You can do any number of the following operations in any order: if |a|>0 (the length of the string a is greater than zero), delete the first character

WANGJOG的博客 560

为什么传统CNN在视网膜分割中败给Mamba?从血管拓扑学揭秘Serp-Mamba的蛇形扫描黑科技

本文深入分析了传统CNN在视网膜血管分割任务中的局限性,特别是在处理高分辨率图像和复杂血管拓扑结构时。针对这些问题,文章重点介绍了Serp-Mamba模型的核心创新——蛇形交织自适应扫描(SIA)机制,该机制通过让扫描路径自适应地贴合血管曲率,并结合模糊驱动双重校准(ADDR)模块应对极端类别失衡,从而在视网膜血管分割任务上实现了性能的显著突破。

ss78901的博客 895

水文仿真软件:HEC-RAS (Hydrologic Engineering Center‘s River Analysis System)_(7).一维非稳态水力模型

自定义脚本是通过编程语言(如 Python)编写的一系列自动化任务,可以帮助用户更高效地处理数据和运行模型。编写脚本:使用 Python 或其他编程语言编写自定义脚本。集成脚本:将脚本集成到 HEC-RAS 中,实现自动化数据处理和模型运行。

kkchenjj的博客 933

Codeforces Round #674 (Div. 3) F. Number of Subsequences

F. Number of Subsequences Description You are given a string s consisting of lowercase Latin letters “a”, “b” and “c” and question marks “?”. Let the number of question marks in the string s be k. Let’s replace each question mark with one of the letters “a

five_east_west的博客 220

ERROR: Ignored the following yanked versions: 0.8.3, 0.10.19.dev18 的解决办法

关于这个问题,博主是在进行项目中的python依赖包安装的时候遇见的,遇到的异常:关于这个问题,是在。

Spring Boot-Common On With You 643

You Are Given Some Strings...【AC自动机】

题目链接:http://codeforces.com/contest/1202/problem/E 枚举文本串的每个位置,计算以该位置为结尾可以匹配多少个模式串,再计算以下一位置为起点能匹配多少模式串,相乘累加作为答案。 #include <bits/stdc++.h> #define rep(i, a, b) for(int i = (a); i <= (b); i++)...

蒟蒻 lxw的博客 675

秃鹰搜索优化算法(BES)详解:从自然捕食到全局优化

秃鹰搜索优化算法(Bald Eagle Search Optimization Algorithm,BES)是由马来西亚学者Alsattar等人于2020年提出的一种新型元启发式优化算法。该算法灵感来源于秃鹰在自然界中高超的捕食行为,特别是其独特的狩猎策略和卓越的视觉搜索能力,模拟了秃鹰捕食鲑鱼等猎物的完整过程。

qq_42212808的博客 1353

AI应用架构师收藏:大规模AI系统AIOps智能运维的4个落地案例

本文精选互联网、金融、制造、电信四大行业的大规模AI系统AIOps落地案例,覆盖云原生AI平台、风控AI系统、工业AI质检、5G网络AI优化等典型场景。行业背景与系统规模:业务目标、AI系统架构、运维挑战;AIOps解决方案设计:数据采集层→分析层→决策层的全栈架构,技术栈选型与理由;核心技术实现细节:异常检测算法、根因分析模型、自动化恢复流程(含Python代码示例);实施效果与经验总结:关键指标对比、踩坑教训、架构师视角的最佳实践。

AI天才研究院 856

ABC

题目描述 You are given a string s consisting of A, B and C. Snuke wants to perform the following operation on s as many times as possible: Choose a contiguous substring of s that reads ABC and replace it ...

eazo的博客 265

高通IPA硬件加速介绍

‌ 高通IPA (Internet Protocol Accelerator)模块是一种硬件加速模块,由高通公司(Qualcomm)提供,主要用于优化移动设备上的网络数据传输,特别是通过 LTE 、 5G 等移动网络的数据传输‌‌。IPA模块通过硬件加速,显著提高了数据传输的速度和效率,同时降低了设备的功耗,并提供了更稳定的网络连接,减少了数据传输中的丢包和延迟‌。

四儿家的小祖宗的博客 1625

Codeforces Round #710 (Div. 3)C. Double-ended Strings

C. Double-ended Strings time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given the strings a and b, consisting of lowercase Latin letters. You can do any number of the following operations in

p15008340649的博客 253

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Codeforces Round #710 (Div. 3) C. Double-ended Strings

题解: 暴力枚举 #include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { string a,b; cin>>a>>b; int n=a.size(); int m=b.size(); if(n<m) swap(a,b),swap(n,m); map<int,string> s; int co

sjjzslhhh的博客 149

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Codeforces Round #710 (Div. 3) C. Double-ended Strings(暴力、哈希)

这题本质上是lcs,但是比赛的时候直接暴力了,数据范围过小,直接n3枚举存map然后暴力算答案 #include<bits/stdc++.h> using namespace std; #define ll long long const int N=1e5+10; ll t; int main(){ cin>>t; while(t--){ string a,b; map<string,int>pa,pb; cin>>a>&gt..

菱形继承 262

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces Round #710 (Div. 3) 题解

文章目录前言A. Strange TableB. Partial ReplacementC. Double-ended StringsD. Epic Transformation总结 前言 蒟蒻又来发题解了,今天也是来补题的一天 QWQ A. Strange Table 题目的大致意思:原来有n行m列的数字,现在指定一个数字,记住它现在的位置。将这些数字改为m行n列排列,原来指定数字所在位置现在的数字是多少。 解题思路:先记录指定数字的行,列,改变排列方式之后无非是把一行有的数字个数和一列有的数字个数互

lfy0的博客 292

Double-ended Strings | Codeforces

Double-ended Strings from Codeforces Round #710 (Div. 3) Time limit:2s Memory limit:256MB 暴力解决就好,这个题目的意思就是查找最大相同子串,我们可以选择的子串长度为(1)到(ab长度最小值),然后在a和b中选择不同的子串,判断能否找到该长度的相同子串。最后把ab都剔除为该长度的子串就ok了 ac代码: #include<iostream> #include<string> #inclu

Alan_Lowe 246

codeforces710c

幻方,这个就是,题意是,用1~n方个数,来构造,横行,竖行,斜行,都是奇数。 你可以这样啊,就是,让奇数构造在正方形中形成一个菱形。以五为例,第一行,中间1个奇数,第二行,中间3个奇数,第三个行,中间5个奇数。第四行中间3个奇数,第五行中间1个奇数#include<cstdio> #include<cstring> #include<algorithm> using namespace std;

就是想多赚点币子 597

Double-ended Strings

Double-ended Strings Codeforces-1506C 2021.05.01 训练题D **题目大意:**给定一组(两行)字符串,两个字符串可以进行操作:从头部删除字符或者从尾部删除字符,找到最终两个字符串相等时删除的最小字符数 **做题思路:**这道题考察两个字符串的最长公共子串,串的长度为20,可以暴力破解,将短的字符串分解成所有字串,然后在长串中找是否有,取长度最长的情况即可 题目: You are given the strings a and b, consisting of

weixin_45817187的博客 212

Codeforces Round #710 (Div. 3) ABCDE 题解

我的博客园传送门,看的方便些 A. Strange Table 签到题,算出对应行列即可。 view code #include<iostream> #include<string> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include <queue> #include<s

待到山花烂漫时 693

You are given a string S consisting of uppercase English letters and digits. Determine whether S satisfies the following conditi

题目给定了一个由大写字母和数字组成的字符串S。确定S是否满足以下条件。S是以下字符和字符串的连接,按列出的顺序。一个大写英文字母一个长度为6的字符串,表示100000到999999之间的整数的十进制表示法一个大写英文字母 可以使用C语言来解决这个问题。 首先,我们需要检查S是否以大写字母开头,然后检查S的第二部分是否是6位长的数字字符串,并且这个数字在100000到999999之间。最后,我们还需...

weixin_35750953的博客 354

C - Double-ended Strings

C - Double-ended Strings题解 题解: 题意中让找出在字符串a==b(注意:当a,b字符串都为空时也视为相等),给出的操作方式就是删除,所以我们只需要找出他们相同的子串,求出子串的长度,然后用他们两个原字符串长度求和再减去相同子串长度的二倍就是剩下该删除的也就是求出的操作步数。 #include<iostream> #include<math.h> using namespace std; int main() { int t; cin&.

Prime me的博客 260

CF1506C Double-ended Strings(差不多就是找最长串问题)

题目描述 You are given the stringsaaandbb, consisting of lowercase Latin letters. You can do any number of the following operations in any order: if|a| > 0∣a∣>0(the length of the stringaais greater than zero), delete the first character of the ...

胜神明半子 314

ABC(思维)

题目描述 You are given a string s consisting of A, B and C. Snuke wants to perform the following operation on s as many times as possible: Choose a contiguous substring of s that reads ABC and replace it...

永夜莫明的博客 355
上一篇: Codeforces Round #618 (Div. 2), problem: (C) Anu Has a Function
下一篇: 牛客暑期多校第一场
阿汤太菜了
博客等级 码龄6年 4粉丝 19原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值