#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. HDP2.0测试

    1.测试Hbase (1)hive导入hbase

  2. mysql修改记录

    增加一列:alter table bf_agt_dep_acct_sap_sub add column cust_age varchar(10) not null; 改变属性:alter table ...

  3. ul 和 ol 标签的相关设置

    初学者不喜欢 ul 标签的最重要一点莫过于其前面的黑点了,每次写个无序列表其前面总有一个黑点是个很讨厌的事,去掉黑点的话自然是要用到 list-style:none:这条css 属性设置了. p.p1 ...

  4. R-CNN算法概要

    参考论文:Rich feature hierarchies for accurate object detection and semantic segmentation 下载地址:https://a ...

  5. 【前端】JavaScript中prototype和__proto__的区别

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/prototype.html 经常有小伙伴问我关于prototype和__proto__的问题,觉得有必要写一篇博客 ...

  6. R语言︱噪声数据处理、数据分组——分箱法(离散化、等级化)

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 分箱法在实际案例操作过程中较为常见,能够将一些 ...

  7. 集成电路883和883b有什么区别

    根据用途,元器件的质量等级可分为:用于元器件生产控制.选择和采购的质量等级和用于电子设备可靠性预计的质量等级两类,两者有所区别,又相互联系. 用于元器件生产控制.选择和采购的质量等级 元器件的质量等级 ...

  8. [php] php操作xml

    xml文件 <?xml version="1.0" encoding="ISO-8859-1"?> <root> <item id ...

  9. TypeError: Error #1034: 强制转换类型失败:无法将 flash.events::MouseEvent@73b7cc1 转换为 mx.events.ItemClickEvent。

    1.错误描述 TypeError: Error #1034: 强制转换类型失败:无法将 flash.events::MouseEvent@73b7cc1 转换为 mx.events.ItemClick ...

  10. C++遍历二维数组的四种方法

    #include <iostream> using std::cin; using std::cout; using std::endl; using std::string; using ...