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的更多相关文章

  1. CF - 1117 F Crisp String

    题目传送门 题解: 枚举非法对. 如果 ‘a'  和 ’b' 不能相邻的话,那么删除 'a' 'b'之间的字符就是非法操作了. 假设题目给定的字符串为 "acdbe",所以删除cd ...

  2. cf 710 E Generate a String

    题意: 开始你有数字$0$,你可以用代价$x$将该数字加$1$或减$1$(当$x > 0$时),或用代价$y$将该数字变为$2x$,那么问得到数字$n$所需的最少代价是多少. 数据范围$1 \l ...

  3. CF1117E Decypher the String

    如果我们能询问一个排列的话,我们就可以得到这个置换,然后反向求解. 但现在字符集只有26. 考虑26^3>1e5. 用一个三维坐标去映射到一个一维整数,然后就可以构造排列了. #include& ...

  4. CF 914F Substrings in a String——bitset处理匹配

    题目:http://codeforces.com/contest/914/problem/F 可以对原字符串的每种字母开一个 bitset .第 i 位的 1 表示这种字母在第 i 位出现了. 考虑能 ...

  5. cf round 598div3 D.Binary String Minimizing

    题目:https://codeforces.com/contest/1256/problem/D 题意:给你长度为n的01串,能将任意两相邻字符交换k次,求最小字典序的交换结果. 思路:贪心...甚至 ...

  6. Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String

    题目大意:这是一道交互题.给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3 ...

  7. CF集萃2

    CF1155D - Beautiful Array 题意:给你一个序列和x,你可以选择任意一个子串(可以为空)乘上x,使得得到的序列最大子串和最大.求这个最大值.30w,2s. 解:设fi,0/1/2 ...

  8. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

  9. hbase开发实例

    1.put/checkAndPut package com.testdata; import java.io.IOException; import org.apache.hadoop.conf.Co ...

随机推荐

  1. sqlserver的资源调控器

    参考SQL Server2014管理最佳实战,所做的笔记. 1:创建资源池 use master go create resource pool poolAdhoc with ( min_cpu_pe ...

  2. Invalid argument during startup: unknown conf file parameter : requirepass

    redis 设置来密码,出现来这个错误, 把配置文件那一行的 空格 去掉 # requirepass foobared 改成 requirepass 123456 因为# 和 requirepass ...

  3. python2.7下同步华为云照片的爬虫程序实现

    1.背景 随着华为手机的销量加大,华为云的捆绑服务使用量也越来越广泛,华为云支持自动同步照片.通讯录.记事本等,用着确实也挺方便的,云服务带来方便的同时,也带来了数据管理风险.华为目前只提供一个www ...

  4. 基于php-fpm的配置详解

    php5.3自带php-fpm/usr/local/php/etc/php-fpm.confpid = run/php-fpm.pidpid设置,默认在安装目录中的var/run/php-fpm.pi ...

  5. (1)访问控制 (2)final关键字 (3)对象创建的过程 (4)多态

    1.访问控制(笔试题)1.1 常用的访问控制符 public - 公有的 protected - 保护的 啥也不写 - 默认的 private - 私有的 1.2 访问控制符的比较 访问控制符 访问权 ...

  6. Connection:Keep-alive

    名词解释: HTTP无状态:无状态是指协议对于事务处理没有记忆能力,服务器不知道客户端是什么状态.从另一方面讲,打开一个服务器上的网页和你之前打开这个服务器上的网页之间没有任何联系 如果你要实现一个购 ...

  7. Kubernetes dashboard 配置

    安装前准备 下载dashboard的yaml文件 wget -O kube-dashboard.yaml https://git.io/kube-dashboard-no-rbac 这个版本是没有权限 ...

  8. [19/05/03-星期五] GOF23_模式总结

    总结:

  9. Zookeeper入门(四)之Leader选举

    让我们分析如何在ZooKeeper集合中选举leader节点.考虑一个集群中有N个节点.leader选举的过程如下: 所有节点创建具有相同路径 /app/leader_election/guid_ 的 ...

  10. Plugin with id 'com.novoda.bintray-release' not found的解决方法

    我们一般在在github上下载下来的代码,有时候会提示Plugin with id ‘com.novoda.bintray-release’ not found的错误,这个怎么解决呢,其实很简单,只要 ...