#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. java8在Collection中新增加的方法removeIf

    记得我在以前找工作的经历中,遇到过一个面试官问过我一个很基础的问题.问题是:有一个List中有10个元素,我现在想从中删除3个元素,请问怎么做?我当时也没想,就直接说,List的有自带的remove方 ...

  2. Flask Ansible自动化平台搭建(持续更新)

    一:简介 使用Ansible + Flask + Celery搭建web平台. 目录结构 . ├── ansible_api │   ├── ansible_playbook_inventory.py ...

  3. KVM虚拟化网络优化技术总结

    https://www.intel.com/content/dam/www/public/us/en/documents/technology-briefs/sr-iov-nfv-tech-brief ...

  4. linux Nagios监控

    监控目标 监控目标主机分为四个部分 硬件资源 操作系统 数据库 应用软件 监控目的: 进行服务器性能调整前,知道调整什么,系统瓶颈在什么地方 被一部分必须同时监控,内容包括吞吐量,反应时间,使用率等 ...

  5. linux dns子域授权 split分离解析 缓存dns服务器

    DNS子域授权作用:适用于同一个DNS组织父/子域名的解析工作由不同的dns服务器负责父dns服务器应该有为子域名迭代的能力 上下级区域属于不同的机构管理:.cn与.Anonymous.cn.cn需要 ...

  6. 在Ubuntu 中使用Source Code Pro字体

    1.下载字体 推荐GitHub上面的项目主页上下载 Source Code Pro 2.解压 unzip SourceCodePro_FontsOnly-1.013.zip 3. 打开SourceCo ...

  7. HighCharts之2D柱状图、折线图的组合多轴图

    HighCharts之2D柱状图.折线图的组合多轴图 1.实例源码 SomeAxis.html: <!DOCTYPE html> <html> <head> < ...

  8. 从1.5K到18K,一个程序员的5年成长之路

    原文地址:点击打开链接 168楼朋友批评的很有道理, 虚心接受. 我自己是开始学的时候已经错过了基础课的学习, 现在也是深受其苦的, 面临技术上的瓶颈, 需要花更多的时间补充这些知识. 希望看到此文的 ...

  9. Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope

    1.错误描述 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.tes ...

  10. Django学习-4-request获取数据

    app下views.py             获取前端HTML数据的一些方法             def func(request):                 # request.me ...