首页 技术 正文
技术 2022年11月11日
0 收藏 459 点赞 4,547 浏览 1005 个字

题意略。

思路:

这个题目没做出来是因为缺少一个整体的构造思路。

正确的构造思路是不断地在s中去构造并且扩大t的后缀,构造好的后缀总是放在前面,然后不断地把它往后挤,最后将s构造成t。

比如:

现在在s中构造好的t的后缀为a(在s中体现为前缀),包含在了s的前缀中,为了继续扩大这个t的后缀,我们需要将z添加到A前。

也就是AzB,要把z添加到A前,保持a不动,a为A的前缀,也是t的构造好的后缀。

AzB — B`zA` — AB`z — zAB`    一共需要3次动作。

如果t的长度为len,那么我只需要3 * n次动作就可以完成了。

n最长又是2000,所以我们最多只需要6000次动作就可以了。小于6100,因此只要s和t的字符种类和个数一样就可以合法构造了。

详见代码:

#include<bits/stdc++.h>
using namespace std;string s,t,s1,t1,str1,str2,str3;
int len;
vector<int> ans;int main(){
std::ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin>>len;
cin>>s>>t;
s1 = s,t1 = t;
sort(s1.begin(),s1.end());
sort(t1.begin(),t1.end());
if(s1 != t1){
cout<<-<<endl;
return ;
}
for(int i = len - ;i >= ;--i){
str1 = str2 = str3 = "";
bool jud = false;
str2 = t[i];
for(int j = ;j < len;++j){
if(jud){
str3 += s[j];
continue;
}
if(s[j] == t[i] && j >= (len - - i)){
jud = true;
continue;
}
if(!jud) str1 += s[j];
}
reverse(str3.begin(),str3.end());
s = str2 + str1 + str3;
ans.push_back(len);
ans.push_back(str1.length());
ans.push_back();
}
cout<< * len<<endl;
for(int i = ;i < ans.size();++i){
cout<<ans[i];
if(i < ans.size() - ) cout<<' ';
else cout<<endl;
}
return ;
}
下一篇: HDU 6059
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844