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. 对MBProgressHUD进行二次封装并精简使用

    对MBProgressHUD进行二次封装并精简使用 https://github.com/jdg/MBProgressHUD 几个效果图: 以下源码是MBProgressHUD支持最新的iOS8的版本 ...

  2. [UI] 精美UI界面欣赏[1]

    精美UI界面欣赏[1]

  3. iOS手势处理

    iOS手势处理 iOS手势有着如下几种: UITapGestureRecognizer UIPinchGestureRecognizer UIRotationGestureRecognizer UIS ...

  4. Python学习---IO的异步[自定义异步IO]

    自定义IO异步基础知识: --所有的请求都基于socket实现,一个请求就是一个socket socket.setblocking(False) 不需要阻塞,一个请求完了发送另外一个,会报错,需解决 ...

  5. 将亚马逊aws的ec2服务器的登陆方式改为密码登陆

    1.在用密钥登陆ec2后,为root用户创建密码: sudo passwd root 系统会让你输入两次密码 2.切换为root用户,并且编辑sshd_config文件,PasswordAuthent ...

  6. December 03rd 2016 Week 49th Saturday

    By failing to prepare, you are preparing to fail. 不做准备,那就准备失败吧. How does the case when you had prepa ...

  7. /dev/urandom非阻塞的发生器

    JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom" /dev/urandom   /dev/urandom ...

  8. 《信息安全技术》实验一 PGP的原理与使用

    <信息安全技术>实验一 PGP的原理与使用(macOS High Sierra下实现) 实验目的 理解传统加密.公钥加密.混合加密.数字签名等概念 理解公钥.私钥.会话密钥.对称密钥等概念 ...

  9. Jenkins启动和停止服务

    1.怎么启动Jenkins? step1:进入到Jenkins的war包所在的目录. 如果是win7及以上版本,直接打开Jenkins的war包所在的目录,在地址栏敲cmd,回车. 上述结果和进入cm ...

  10. Opencv——级联分类器(AdaBoost)

    API说明: cv::CascadeClassifier::detectMultiScale(InputArray image,//输入灰度图像 CV_OUT std::vector<Rect& ...