#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. 使用C#解决部分Win8.1系统窗口每隔几秒失去焦点的问题【转】

    使用了Win8.1 With Update 1后,发现重启系统后,当前激活的窗口总是每隔几秒失去焦点,过0.5~1秒焦点回来,导致输入无法正常工作,严重影响使用心情和效率. 在网上找了很久,也没找到相 ...

  2. java容器类分析:Collection,List,ArrayList

    1. Iterable 与 Iterator Iterable 是个接口,实现此接口使集合对象可以通过迭代器遍历自身元素. public interface Iterable<T> 修饰符 ...

  3. Android视频播放的两种方式介绍

    1.在Android 中播放视频的方式有两种: 第一种方式是使用MediaPlayer 结合SurfaceView 来播放,通过MediaPlayer来控制视频的播放.暂停.进度等: 通过Surfac ...

  4. [php]在PHP中读取和写入WORD文档的代码

    测试平台windows 使用的windows的com主键. <? // 建立一个指向新COM组件的索引 $word = new COM("word.application") ...

  5. java.io.FileNotFoundException: /opt/apache-tomcat-7.0.57/conf/server.xml (权限不够)

    1 错误描述 youhaidong@youhaidong:~$ cd /opt/apache-tomcat-7.0.57 youhaidong@youhaidong:/opt/apache-tomca ...

  6. TypeError: Error #1034: 强制转换类型失败:无法将 mx.controls::DataGrid@9a7c0a1 转换为 spark.core.IViewport。

    1.错误描述 TypeError: Error #1034: 强制转换类型失败:无法将 mx.controls::DataGrid@9aa90a1 转换为 spark.core.IViewport. ...

  7. OpenStack_I版 6.Neutron部署

    Neutron是不能自己创建网络的,它需要借助插件才能创建虚拟网桥.网卡 依赖插件 配置ml2为核心插件 本次网络模型采用扁平化网络,不同的网络类型不同的配置,不同的使用方法 打开安全组功能 Linu ...

  8. CentOS中对ext4文件系统做磁盘配额

    1.修改/etc/fstab文件,使ext4文件系统支持磁盘配额. UUID="9e6dc1e8-4fc1-4984-be38-524573572d41" /mnt/ext ext ...

  9. WPF基础篇之连接数据库

    WPF连接DB2数据库 public void ConnectionBD2Func() { //连接数据库字符串,DB2 9.5以下版本使用Data Source=Test,否则查询找不到数据库.DB ...

  10. ListView添加item的事件监听

    1. 点击事件(OnItemClickListener) onItemClick(AdapterView<?> parent, View view, int position, long ...