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 ...
 
随机推荐
- js 格式化时间、字符串指定长度、随机字符串
			
格式化字符串长度 方法 function formatWidth(str, width){ str += '' if(str.length<width) '+str, width) else r ...
 - C++常量 运算符
			
\n 换行 光标移到下一行 \0 空值 \t 水平制表符 \r 回车 光标回到本行开头 ...
 - JavaScript之Ajax(一)创建Ajax对象
			
// 支持浏览器的源码 function AjaxObject() { var AjaxRequest; // 缓存XHR对象便于 Ajax 使用 try { // Opera 8.0+, Firef ...
 - [洛谷P3948]数据结构 题解(差分)
			
[洛谷P3948]数据结构 Description 最开始的数组每个元素都是0 给出n,opt ,min,max,mod 在int范围内 A: L ,R ,X 表示把[l,R] 这个区间加上X(数组的 ...
 - Django学习手册 - ORM choice字段 如何在页面上显示值
			
在module操作过程中使用choice字段: 核心: obj.get_字段名_display 定义module 数据结构: class msg(models.Model): choice = ( ( ...
 - mysql一次查询,返回多个统计结果
			
1.sum(if) select sum(if(status=1,1,0)) as s1_count,sum(if(status=2,1,0)) as s2_countfrom order; 2.co ...
 - ubuntu下安装pdf编辑器Master PDF Editor
			
在 ubuntu 上看一些 pdf 文档,自带的pdf阅读器不带编辑功能.推荐使用 master pdf editor 1. 安装QT sudo apt-get install qt-sdk 2. 下 ...
 - c语言的重构、清理与代码分析图形化浏览工具: CScout
			
网址: https://www.spinellis.gr/cscout/ https://www2.dmst.aueb.gr/dds/cscout/index.html https://github. ...
 - 编写html与js交互网页心得:编写两个按钮切换显示不同的图片
			
第一步:先建立一个html网页,如下: <!DOCTYPE html><html> <head> <meta charset="utf-8&quo ...
 - python环境下使用tab自动补全命令
			
# vim /usr/lib/python2.7/dist-packages/tab.py 加入如下内容: #!/usr/bin/env python # python startup file im ...