Codeforces Round #467 (Div. 2) E -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的更多相关文章
- Codeforces Round #467 (Div. 1). C - Lock Puzzle
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> ...
- Codeforces Round #467 (div.2)
Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...
- Codeforces Round #467 Div.2题解
A. Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 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 ...
- 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 ...
- Codeforces Round #467 (Div. 1) B. Sleepy Game
我一开始把题目看错了 我以为是博弈.. 这题就是一个简单的判环+dfs(不简单,挺烦的一题) #include <algorithm> #include <cstdio> #i ...
- Codeforces Round #467 Div. 1
B:显然即相当于能否找一条有长度为奇数的路径使得终点出度为0.如果没有环直接dp即可.有环的话可以考虑死了的spfa,由于每个点我们至多只需要让其入队两次,复杂度变成了优秀的O(kE).事实上就是拆点 ...
- 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 ...
- 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 ...
随机推荐
- centos shell运行报语法错误: 未预期的文件结尾
可能原因: 脚本是windows下写的,然后传到linux下运行的 需要给dos文件格式转成unix dos转unix 安装: yum install dos2unix 命令: dos2unix fi ...
- u-boot移植(八)---代码修改---存储控制器--MMU
一.MMU介绍 1.1 虚拟地址与物理地址 建立两个应用程序,hello1.c和hello2.c,然后运行: hello1.c hello2.c 运行结果如下: 可以看到两个结果打印的地址是一样的,都 ...
- android数据库简单操作
1.DbOpenHelper package com.example.dbtest.dbHelper; import android.content.Context; import android.d ...
- oracle数据库还原以及备份 包括快速备份(并发压缩)
expdp jhpt/XXXX directory=databackup dumpfile=dpfile_201512091300_%U.dmp filesize=5G parallel=8 comp ...
- 第16月第31天 mongo
1. 94 brew install mongodb 95 cd ~ 96 cd Desktop/web/ 97 ls 98 mkdir mongo 99 cd mongo/ 100 ...
- snmp 发送类型ASN_OBJECT_ID
参考链接: http://blog.csdn.net/yin138/article/details/50388878 ,,,,,,,,,}; int ret = snmp_set_var_typed_ ...
- 一:对程序员来说CPU是什么?
0.开篇 (1)程序是什么? 指示计算机每一步动作的一组指令 (2)程序是由什么组成的? 指令和数据 (3)什么是机器语言? ...
- STM32 变量无法赋值问题
STM32 在用JLink 调试的时候发现有一条将unsigned char赋值给int的语句始终不能执行,int类型变量的值始终为0: 查资料找到这个问题是编译器优化的原因,也就是说由于编译器优化, ...
- SpringBoot PUT请求
(1)配置HiddenHttpMethodFilter(SpringMVC需要配置,SpringBoot已经为我们自动配置了) (2)在视图页面创建一个Post Form表单,在表单中创建一个inpu ...
- 生成ansible-playbook的yaml文件的代码(字典排序问题无法解决)
import yaml import collections def add_task(): return None def add_vars(): return None def add_handl ...