CF 1117 E. Decypher the String
E. Decypher the String
题意:
有一个字符串,一些操作,每次操作交换两个位置的字符,经过这些操作后,会得到新的字符串。给你新的字符串,求原来的串。可以有3次询问,每次询问给出一个字符串,返回操作后的字符串。
分析:
如果长度小于等于26,那么询问abc...xyz,就可以知道每个位置操作后的对应的位置。那么长度大于26的时候,考虑均分成26段,每段是一个字符,然后可以知道每段对应的位置集合。继续在每一段内均分即可,均分3次,即可到单个位置。
代码实现很有意思,写成一个26进制数。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
char s[N], s1[N], s2[N], s3[N], ans[N];
bitset<N> a1[], a2[], a3[], now;
int pos[N]; int main() {
scanf("%s",s);
int n = strlen(s);
for (int i = ; i< n; ++i) {
int t = i;
s1[i] = 'a' + t % ; t /= ;
s2[i] = 'a' + t % ; t /= ;
s3[i] = 'a' + t % ; t /= ;
}
printf("? "); puts(s1); fflush(stdout); scanf("%s", s1);
printf("? "); puts(s2); fflush(stdout); scanf("%s", s2);
printf("? "); puts(s3); fflush(stdout); scanf("%s", s3); for (int i = ; i < n; ++i) a1[s1[i] - 'a'].set(i);
for (int i = ; i < n; ++i) a2[s2[i] - 'a'].set(i);
for (int i = ; i < n; ++i) a3[s3[i] - 'a'].set(i); for (int i = ; i < n; ++i) {
int t = i;
now = a1[t % ]; t /= ;
now &= a2[t % ]; t /= ;
now &= a3[t % ]; t /= ;
for (int j = ; j < n; ++j)
if (now[j]) { pos[i] = j; break; }
}
for (int i = ; i < n; ++i) ans[i] = s[pos[i]];
printf("! %s\n", ans);
return ;
}
CF 1117 E. Decypher the String的更多相关文章
- CF - 1117 F Crisp String
题目传送门 题解: 枚举非法对. 如果 ‘a' 和 ’b' 不能相邻的话,那么删除 'a' 'b'之间的字符就是非法操作了. 假设题目给定的字符串为 "acdbe",所以删除cd ...
- cf 710 E Generate a String
题意: 开始你有数字$0$,你可以用代价$x$将该数字加$1$或减$1$(当$x > 0$时),或用代价$y$将该数字变为$2x$,那么问得到数字$n$所需的最少代价是多少. 数据范围$1 \l ...
- CF1117E Decypher the String
如果我们能询问一个排列的话,我们就可以得到这个置换,然后反向求解. 但现在字符集只有26. 考虑26^3>1e5. 用一个三维坐标去映射到一个一维整数,然后就可以构造排列了. #include& ...
- CF 914F Substrings in a String——bitset处理匹配
题目:http://codeforces.com/contest/914/problem/F 可以对原字符串的每种字母开一个 bitset .第 i 位的 1 表示这种字母在第 i 位出现了. 考虑能 ...
- cf round 598div3 D.Binary String Minimizing
题目:https://codeforces.com/contest/1256/problem/D 题意:给你长度为n的01串,能将任意两相邻字符交换k次,求最小字典序的交换结果. 思路:贪心...甚至 ...
- Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String
题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3 ...
- CF集萃2
CF1155D - Beautiful Array 题意:给你一个序列和x,你可以选择任意一个子串(可以为空)乘上x,使得得到的序列最大子串和最大.求这个最大值.30w,2s. 解:设fi,0/1/2 ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
- hbase开发实例
1.put/checkAndPut package com.testdata; import java.io.IOException; import org.apache.hadoop.conf.Co ...
随机推荐
- MySQL: OPTIMIZE TABLE: Table does not support optimize, doing recreate + analyze instead
show create table history;-------------------------- CREATE TABLE `foo` ( `itemid` bigint(20) unsig ...
- 处理过期的archivelog和rman备份
当手工删除了归档日志以后,Rman备份会检测到日志缺失,从而无法进一步继续执行.所以此时需要手工执行crosscheck过程,之后Rman备份可以恢复正常.[执行顺序如下:手工删除archivelog ...
- Spring 利用PropertyPlaceholderConfigurer占位符
Hey Girl 博客园 首页 博问 闪存 新随笔 订阅 管理 posts - 42, comments - 3, trackbacks - 0 Sp ...
- jQuery 和 YUI (Yahoo User Interface) 各自的优缺点有哪些?具体的使用场景是怎样的?
张经纬,前端工程师 知乎用户.赵勇杰.知乎用户 等人赞同 其实jQuery和YUI的侧重点是不一样的. jQuery专注于DOM的操作,他通过继承的方式给传入的对象增加了新的方法,从而使我们可以通过链 ...
- ubuntu16.04中安装下载工具uget+aria2并配置chrome (stable版)
1.安装uGut sudo apt-get install uget 2.安装aria2 sudo apt-get install arias 3.配置uGet默认下载插件为aria2 菜单栏依次打开 ...
- orge资源
1. OGRE官网 http://www.ogre3d.org (重要) 2. OGRE WIKI http://www.ogre3d.org/wiki/index.php/Main_Page( ...
- Hadoop学习之路(三)Hadoop-2.7.5在CentOS-6.7上的编译
下载Hadoop源码 1.登录官网 2.确定你要安装的软件的版本 一个选取原则: 不新不旧的稳定版本 几个标准: 1)一般来说,刚刚发布的大版本都是有很多问题 2)应该选择某个大版本中的最后一个小版本 ...
- pip问题解决方案
错误信息:usr/bin/pip: No such file or directory 解决办法(一共四步,按照下面的步骤来从1到4,最后你会发现问题都解决了): 1.which pip /usr/l ...
- c++——类和对象初探
2.1 基本概念 1)类.对象.成员变量.成员函数 2)面向对象三大概念 封装.继承.多态 3)编程实践 类的定义和对象的定义,对象的使用 求圆形的面积 定义Teacher类,打印Teacher的信息 ...
- bootstrap 多选款样式:bootstrap-switch
有时候,为了美化checkbox后者radio的时候,让用户体验起来更好,jquery里有icheck. bootstrap里有bootstrap-switch,就简单介绍下bootstrap-swi ...