#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
const int maxLength = 2005; char s[maxLength], t[maxLength];
int letterOfS[30];
int letterOfT[30];
std::vector<int> result;
void shift(char* seqence, int location) {
std::string tt = seqence;
tt = tt.substr(location) + tt.substr(0, location);
std::reverse(tt.begin(), tt.begin() + tt.length() - location);
for (int i = 0, length = tt.length(); i < length; ++i) {
seqence[i] = tt[i];
}
// seqence[tt.length()] = 0; result.push_back(tt.length() - location);
// printf("%s\n", seqence);
}
void solveChange(int length) {
int okLength = 0;
for (int i = 0; i < length; ++i) {
char targetLetter = t[i];
int LocationOftargetInS;
for (int j = 0; j < length - i; ++j) {
if (s[j] == targetLetter) {
LocationOftargetInS = j;
break;
}
}
// printf("%d\n", LocationOftargetInS);
shift(s, LocationOftargetInS + 1);
shift(s, length - 1);
shift(s, 0);
// printf("\n");
}
} int main() {
int n;
while (~scanf("%d", &n)) {
result.clear();
memset(letterOfS, 0, sizeof(letterOfS));
memset(letterOfT, 0, sizeof(letterOfT)); scanf("%s %s", s, t);
for (int i = 0; i < n; ++i) {
letterOfS[s[i] - 'a']++;
}
for (int i = 0; i < n; ++i) {
letterOfT[t[i] - 'a']++;
}
bool canChange = true;
for (int i = 0; i < 26 && canChange; ++i) {
if (letterOfS[i] != letterOfT[i]) {
canChange = false;
}
} if (canChange) {
solveChange(n);
printf("%d\n", (int)result.size());
for (int i = 0; i < result.size(); ++i) {
printf("%d ", result[i]);
}
printf("\n");
} else
printf("-1\n");
}
return 0;
}

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

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

    Lock Puzzle 题目大意:给你两个字符串一个s,一个t,长度<=2000,要求你进行小于等于6100次的shift操作,将s变成t, shift(x)表示将字符串的最后x个字符翻转后放到 ...

  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. SSH服务端配置、优化加速、安全防护

    CentOS7自带的SSH服务是OpenSSH中的一个独立守护进程SSHD.由于使用telnet在网络中是明文传输所以用其管理服务器是非常不安全的不安全,SSH协议族可以用来对服务器的管理以及在计算机 ...

  2. 思科ASA5520防火墙telnet、SSH及DHCP设置

    ASA5520远程登录telnet 注:最低安全级别的接口不支持telnet登陆,如OutsideASA(config)# telnet 172.16.0.0 255.255.0.0 inside   ...

  3. 新手福音︱正则表达式小工具RegExr

    由于之前在做NLP的内容,势必会接触正则表达式,但是呢,又觉得这个学不明白- 于是,这个工具还是蛮不错的,相当于在线正则速查+验证小工具,对于我这样的新手值得去玩玩. github:https://g ...

  4. caffe︱cifar-10数据集quick模型的官方案例

    准备拿几个caffe官方案例用来练习,就看到了caffe中的官方案例有cifar-10数据集.于是练习了一下,在CPU情况下构建quick模型.主要参考博客:liumaolincycle的博客 配置: ...

  5. Caused by: Unable to locate parent package [json-default] for [class com.you.user.action.StudentActi

    1.错误描述 信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.TextParser) 2014-7-13 1:52:04 or ...

  6. Django学习-22-Form

    Form是Django的功能较强的验证组件,负责各种表单验证 input中的name属性值要和form中的字段名相同 from django import forms from django.form ...

  7. JustMock .NET单元测试利器(二)JustMock基础

    JustMock API基础 Mock是Telerik®JustMock框架中的主要类.Mock用于创建实例和静态模拟,安排和验证行为. 本文将介绍 "Mock"的基本用法: 首先 ...

  8. 利用GDI+在Winfrom绘制验证码

    string yzm: private void yangzhengma() { Bitmap bt = new Bitmap(70,22);//创建位图对象 Graphics gs = Graphi ...

  9. 异常-----freemarker.core.ParseException: Encountered "string"

    1.错误描述 freemarker.core.ParseException: Encountered "string" at line 21, column 21 in type. ...

  10. ubuntu安装latex

    1 终端中输入"sudo apt-get install texlive-full",输入root密码. 若不想安装所有文件,可以选择"sudo apt-get inst ...