Lock Puzzle CodeForces - 936C (构造)
大意: 给定字符串$s$,$t$, 每次操作可以将$S=AB$变为$S=B^RA$, 要求$3n$次操作内将$s$变为$t$.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n;
char s[N], t[N];
vector<int> g;
void shift(int x) {
if (!x) return;
reverse(s+1,s+1+n);
reverse(s+x+1,s+1+n);
g.pb(x);
}
int main() {
scanf("%d%s%s", &n, s+1, t+1);
REP(i,1,n) {
int pos = i;
for (; s[pos]!=t[n-i+1]; ++pos) ;
if (pos>n) return puts("-1"),0;
shift(n),shift(pos-1),shift(1);
}
printf("%d\n",int(g.size()));
for (auto &&t:g) printf("%d ", t);hr;
}
Lock Puzzle CodeForces - 936C (构造)的更多相关文章
- Codeforces Round #467 (Div. 2)  E	-Lock Puzzle
		
Lock Puzzle 题目大意:给你两个字符串一个s,一个t,长度<=2000,要求你进行小于等于6100次的shift操作,将s变成t, shift(x)表示将字符串的最后x个字符翻转后放到 ...
 - hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup
		
http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...
 - HDU 4708:Rotation Lock Puzzle
		
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
 - hdu4708 Rotation Lock Puzzle
		
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
 - HDU 4708 Rotation Lock Puzzle (简单题)
		
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
 - HDUOJ---(4708)Rotation Lock Puzzle
		
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
 - Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
		
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
 - CF 936C Lock Puzzle——构造
		
题目:http://codeforces.com/contest/936/problem/C 玩了一个小时,只能想出 5*n 的方法. 经过一番观察?考虑这样构造:已经使得 A 串的一个后缀 = B ...
 - CF936C Lock Puzzle 构造
		
传送门 好久不做构造题脑子都僵化了qwq 无解的条件是\(s\)包含的字符可重集和\(t\)包含的字符可重集不相等,相等的时候下文会给出一种一定可行的构造方案. 考虑增量构造.定义某个字符串\(x\) ...
 
随机推荐
- Riot.js——一个小而美的JS框架
			
Riot.js是什么? Riot 拥有创建现代客户端应用的所有必需的成分: "响应式" 视图层用来创建用户界面 用来在各独立模块之间进行通信的事件库 用来管理URL和浏览器回退按钮 ...
 - LeetCode 230. 二叉搜索树中第K小的元素(Kth Smallest Element in a BST)
			
题目描述 给定一个二叉搜索树,编写一个函数 kthSmallest 来查找其中第 k 个最小的元素. 说明:你可以假设 k 总是有效的,1 ≤ k ≤ 二叉搜索树元素个数. 示例 1: 输入: roo ...
 - System.Runtime.CompilerServices.Unsafe
			
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.CompilerServices.Un ...
 - vue中getters不更新数据解决办法
			
在 Vue.js devtools 中看到,我们明明更改了仓库 state 中的数据,但是我们的 getters 就是值渲染一次之后就不再重新渲染了 解决方法:使用 Vue.set() 方法,就是专门 ...
 - Oracle 中使用正则表达式
			
Oracle使用正则表达式离不开这4个函数: 1.regexp_like select t3.cert_no from table_name t3 where regexp_like(t3.cert_ ...
 - 代码实现:判断E盘目录下是否有后缀名为.jpg的文件,如果有,就输出该文件名称
			
package com.loaderman.test; import java.io.File; import java.io.FilenameFilter; public class Test { ...
 - linux添加用户所在群组
			
etc目录下面有两个文件一个passwd一个grouppasswd里gid是主组,其他组是扩展组,扩展组在/etc/group里描述.useradd username如果不指定,默认创建一个与uid相 ...
 - 五十七:flask文件上传之使用flask-wtf验证上传的文件
			
1.安装:pip install flask-wtf2.定义表单验证的时候,对文件的字段,需使用:FileField3.验证器从flask_wtf.file中导入,FileRequired为验证文件必 ...
 - Redis 高级应用
			
Redis SAVE 命令用于创建当前数据库的备份 该命令将在 redis 安装目录中创建dump.rdb文件. 如果需要恢复数据,只需将备份文件 (dump.rdb) 移动到 redis 安装目录并 ...
 - Java多线程(2):线程加入/join()
			
线程加入 join()方法,等待其他线程终止.在当前线程(主线程)中调用另一个线程(子线程)的join()方法,则当前线程转入阻塞状态,直到另一个线程运行结束,当前线程再由阻塞转为就绪状态. 也就是主 ...