Codeforces 936C
题意略。
思路:
这个题目没做出来是因为缺少一个整体的构造思路。
正确的构造思路是不断地在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 ;
}
Codeforces 936C的更多相关文章
- Lock Puzzle CodeForces - 936C (构造)
大意: 给定字符串$s$,$t$, 每次操作可以将$S=AB$变为$S=B^RA$, 要求$3n$次操作内将$s$变为$t$. #include <iostream> #include & ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 【Java】Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 1099
详细信息如下: Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: ...
- Apache ActiveMQ 实践 <一>
一.下载最新版本 ActiveMq http://activemq.apache.org/activemq-5152-release.html,下载目录如下: 二.创建项目 1.普通项目 添加 jar ...
- oracle的开窗函数
原创 select * from (select province, commodity, sum(price), ROW_NUMBER() OVER(PARTITION BY province o ...
- 【POJ - 2456】Aggressive cows(二分)
Aggressive cows 直接上中文了 Descriptions 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x ...
- C#连接SQL Anywhere 12 数据库
using System;using System.Data.Common; namespace ConsoleApplication27{ class Program { ...
- 4如何用PHP给MySQL数据库添加记录
首先连接数据库(依旧用第二篇的方法) 假设数据库表里只有id,name,email三列 添加以下代码 $inputemail=写你要的email;$inputname=写你要的name;//先设定你要 ...
- hadoop安装解决之道
# 壹.故障现象 ```xml Microsoft Windows [版本 10.0.18362.239] (c) 2019 Microsoft Corporation.保留所有权利. C:\User ...
- mybatis学习笔记(一)
mybatis学习笔记 mybatis简介 Mybatis 开源免费框架.原名叫iBatis,2010在googlecode,2013年迁移到 github 作用: 数据访问层框架,底层对JDBC进行 ...
- css公共样式 | 标签元素初始化
PC参考样式1: @charset "utf-8"; html{background:#fff;overflow:auto;} body{min-width:1200px;font ...
- windows查看端口被占用
1.打开控制台终端 2.在命令行下输入netstat -ano|findstr "8080"(8080是被占用的端口) 3.记住最后一列的数字PID如4684 4.输入taskli ...