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. jaxp实现对xml文档的增,删,改,查操作(附源码)浅析

    jaxp,属于javase中的一部分.是对xml进行解析的一个工具类: 既然说到这里,还是讲全一点,讲讲上面说到的xml的解析技术. xml的一个标记型文档. 在html的层级结构中,它会在内存中分配 ...

  2. android 加载图片

    package mydemo.mycom.demo2; import android.graphics.Bitmap; import android.graphics.BitmapFactory; i ...

  3. luogu P4036 [JSOI2008]火星人

    传送门 很久以前xzz大佬就喊我做这题,结果现在才做qwq 因为要在序列中插入,所以直接用\(Splay\)维护这个串的哈希值,插入就直接把那个点插♂进去,修改就把点旋到根,然后修改和pushup,询 ...

  4. POJ 1200 Crazy Search (哈希)

    题目链接 Description Many people like to solve hard puzzles some of which may lead them to madness. One ...

  5. mysql timestamp时区有影响

    timestamp格式 如果数据库修改时区,可能会对数据影响,datetime不依赖数据库时区

  6. String split方法与Guava Splitter用法区别

    String split方法与Guava Splitter用法区别 今天同事写了一段使用String split方法的代码,如下所示,同事期望得到的是字符"1",但是没想到却得到空 ...

  7. Eclipse通用设置

    分类 Eclipse分为64位.32位,安装版.免安装版 查看Eclipse版本信息 Help - About Eclipse - Installation Details

  8. 卷积神经网络(CNN)学习笔记1:基础入门

    卷积神经网络(CNN)学习笔记1:基础入门 Posted on 2016-03-01   |   In Machine Learning  |   9 Comments  |   14935  Vie ...

  9. Jetson tk1 刷机教程

    前期准备: 1.  Jetson TK1开发板. 2.  安装有ubuntu系统的PC(或者ubuntu虚拟机)切记:不管是PC还是虚拟机,务必确保有大于5G的存储空间,之后安装过程会作详细解释. 3 ...

  10. float/double 浮点数据*100精度丢失问题

    工作中微信支付碰到的一个问题,金额是float数字,微信参数需要分且必须是整数,所以*100的时候就有问题了 System.out.println(9.9f*100); //989.99994Syst ...