Lock Puzzle

题目大意:给你两个字符串一个s,一个t,长度<=2000,要求你进行小于等于6100次的shift操作,将s变成t,

shift(x)表示将字符串的最后x个字符翻转后放到最前面。

思路:不会写,看了题解。。。

因为长度为3000,操作为6500,我们考虑每三次操作将一个字符放到最后,并保证其他字符的顺序不变,这样是可以实现的,

如果我们想要将第k个字符移到最后,我们只要shift(n-1-k) , shift(1) , shift(n-1),就能实现啦 。

 #include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=1e6+;
const int M=; int n;
char s[N],t[N];
vector<int> ans;
void shift(int x)
{
if(x==) return;
reverse(s, s+n);
reverse(s+x, s+n);
ans.push_back(x);
}
int main()
{
read(n);
sread(s); sread(t);
for(int i=;i<n;i++)
{
int now=;
while(s[now]!=t[i])
now++;
if(now>=n-i)
{
puts("-1");
return ;
}
shift(n--now);
shift();
shift(n-);
}
printf("%d\n",ans.size());
for(int i:ans)
printf("%d ",i);
puts("");
return ;
}
/*
*/

Codeforces Round #467 (Div. 2) E -Lock Puzzle的更多相关文章

  1. Codeforces Round #467 (Div. 1). C - Lock Puzzle

    #include <algorithm> #include <cstdio> #include <cstring> #include <iostream> ...

  2. Codeforces Round #467 (div.2)

    Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...

  3. Codeforces Round #467 Div.2题解

    A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  4. Codeforces Round #172 (Div. 2) C. Rectangle Puzzle 数学题几何

    C. Rectangle Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/281/p ...

  5. Codeforces Round #467 (Div. 2) B. Vile Grasshoppers

    2018-03-03 http://codeforces.com/problemset/problem/937/B B. Vile Grasshoppers time limit per test 1 ...

  6. Codeforces Round #467 (Div. 1) B. Sleepy Game

    我一开始把题目看错了 我以为是博弈.. 这题就是一个简单的判环+dfs(不简单,挺烦的一题) #include <algorithm> #include <cstdio> #i ...

  7. Codeforces Round #467 Div. 1

    B:显然即相当于能否找一条有长度为奇数的路径使得终点出度为0.如果没有环直接dp即可.有环的话可以考虑死了的spfa,由于每个点我们至多只需要让其入队两次,复杂度变成了优秀的O(kE).事实上就是拆点 ...

  8. Codeforces Round #467 (Div. 2) B. Vile Grasshoppers[求去掉2-y中所有2-p的数的倍数后剩下的最大值]

    B. Vile Grasshoppers time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #467 (Div. 2) A. Olympiad[输入一组数,求该数列合法的子集个数]

    A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

随机推荐

  1. 二、主目录 Makefile 分析(3)

    2.8 编译选项 重新回到 主 makefile 中执行 2.8.1 u-boot  的编译顺序 代码166 到 189 行,这些是 u-boot 文件编译的顺序,由代码可以看到,首先是从cpu/$( ...

  2. C++ 中 #ifndef, #define, #endif 宏定义

    目的:为了保证包含的内容只被程序(include) 和编译了一次.判断预处理器常量是否已被定义. 预编译将所有头文件(#include"XXX.h")用头文件中的内容来替换,头文件 ...

  3. POJ 2513 Colored Sticks (欧拉回路+并查集+字典树)

    题目链接 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with ...

  4. 后端python基础

  5. JavaScript学习 - 基础(四) - 控制语句/异常处理

    控制语句 if-else 语句 <script> //控制语句 //if-else格式: var x = 1 if(x==1){ console.log("this is if& ...

  6. python - class类 (六) 三大特性 - 多态

    多态的概念: # 多态的概念 # 指出了对象如何通过他们共同的属性和动作来操作及访问而不需考虑他们的具体的类 # 多态表明了动态绑定的存在,允许重载及运行时类型确定和验证. # 示例模拟: #水具有多 ...

  7. C++ socket 传输不同类型数据的四种方式

    使用socket传输组织好的不同类型数据,有四种不同的方式(我知道的嘿嘿): a. 结构体 b. Json序列化 c. 类对象 d. protobuf 下面逐一整理一下,方便以后进行项目开发. 1. ...

  8. CSS选择器中带点(.)怎么办?

    在SharePoint中很多元素的ID都用点(.)来连接的,比如: <li class="ms-cui-group" id="Ribbon.Documents.Ed ...

  9. 使用zabbix3.0.4的ICMP Ping模版实现对客户端网络状态的监控

    一.登陆Zabbix服务器做以下操作: 1.fping安装 wget http://www.fping.org/dist/fping-3.16.tar.gz tar zxvf fping-3.16.t ...

  10. activiti报错ProcessEngines.getDefaultProcessEngine()为null

    activiti报错ProcessEngines.getDefaultProcessEngine()为null 文件名错误,默认加载classpath下面的activiti.cfg.xml,而不是ac ...