Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String
题目大意:这是一道交互题。给你一个长度为n的字符串,这个字符串是经过规则变换的,题目不告诉你变换规则,但是允许你提问3次:每次提问你给出一个长度为n的字符串,程序会返回按变换规则变换后的字符串,提问3次后你需要猜出这个字符串。解法是学习https://blog.csdn.net/baiyifeifei/article/details/87807822 这个博主的,借用了进制的思想非常巧妙。
解法:对于某个位置的来源位置我们设为x,因为26*26*26>10000,那么x可以唯一表示为x=a*26*26+b*26+c。那么我们只要想办法求出a,b,c就能得到它的来源位置。
那么怎么利用三次询问求a,b,c?我们首先构造(26*26个a) (26*26个b) (26*26个c)......(26*26个z),设此位置变换后的字符为c[0],那么a=c[0]-'a'(可以理解为a=x/(26*26)=c[0]-'a')。道理类似的我们下一次构造(26个a) (26个b) (26个c) ......(26个d)的字符串让程序变换,此时变换后的字符为c[1],那么b=c[1]-'a'(可以理解为b=x%(26*26) /26=(b*26+c)/26=c[1]-'a'),这里的b可能有点儿难理解,为什么是这样得到的c[1]就是(b*26+c)/26?因为前一个询问我们已经确定x在a这一个(26*26)的大块里面了,那么我们只需要考虑这个大块,把这个大块再细分为26块看看返回什么值就能知道x在a这个大块的哪一个小块b里面。道理类似的最后构造(abc..z)(abc..z)...(abc..z)得到c=c[2]-'a'。
那么我们就得到该位置的来源是a*26*26+b*26+c,问题得到解决。
如果还是感觉难以理解,可以看看代码再仔细想想:
#include<bits/stdc++.h>
using namespace std;
const int N=+;
int n;
char s[N],q[][N],g[][N],ans[N]; int main()
{
scanf("%s",s);
n=strlen(s);
for (int i=;i<n;i++) {
q[][i]=(i/(*)%+'a');
q[][i]=(i/%+'a');
q[][i]=(i%+'a');
} for (int i=;i<;i++) {
printf("? %s\n",q[i]);
fflush(stdout);
scanf("%s",g[i]);
}
for (int i=;i<n;i++) {
int tmp=(g[][i]-'a')**+(g[][i]-'a')*+(g[][i]-'a');
ans[tmp]=s[i];
}
printf("! %s",ans);
return ;
}
Educational Codeforces Round 60 (Rated for Div. 2) E. Decypher the String的更多相关文章
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
- Educational Codeforces Round 60 (Rated for Div. 2)
A. Best Subsegment 题意 找 连续区间的平均值 满足最大情况下的最长长度 思路:就是看有几个连续的最大值 #include<bits/stdc++.h> using n ...
- Educational Codeforces Round 60 (Rated for Div. 2)D(思维,DP,快速幂)
#include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;unordered_map<long ...
- Educational Codeforces Round 60 (Rated for Div. 2)E(思维,哈希,字符串,交互)
#include <bits/stdc++.h>using namespace std;int main(){ string t; cin>>t; int n=t.size() ...
- Educational Codeforces Round 60 (Rated for Div. 2) 即Codeforces Round 1117 C题 Magic Ship
time limit per test 2 second memory limit per test 256 megabytes input standard inputoutput standard ...
- Educational Codeforces Round 60 (Rated for Div. 2) D. Magic Gems(矩阵快速幂)
题目传送门 题意: 一个魔法水晶可以分裂成m个水晶,求放满n个水晶的方案数(mol1e9+7) 思路: 线性dp,dp[i]=dp[i]+dp[i-m]; 由于n到1e18,所以要用到矩阵快速幂优化 ...
- Educational Codeforces Round 81 (Rated for Div. 2) C. Obtain The String
题目链接:http://codeforces.com/contest/1295/problem/C 题目:给定字符串s,t. 给定一个空串z,需要按照规则把z构造成 string z == stri ...
随机推荐
- 五、Redis五种类型 - 字符串类型
1.介绍: 字符串类型是Redis中最基本的数据类型,可以存储任何形式的字符串数据,最大容量是512MB. key 和 value 都是区分大小写的. 2.命令介绍 (1).赋值: set key v ...
- CUDA学习之二:shared_memory使用,矩阵相乘
CUDA中使用shared_memory可以加速运算,在矩阵乘法中是一个体现. 矩阵C = A * B,正常运算时我们运用 C[i,j] = A[i,:] * B[:,j] 可以计算出结果.但是在CP ...
- 西电源ubuntu12
deb http://linux.xidian.edu.cn/mirrors/ubuntu/ precise main restricted universe multiverse #deb-src ...
- JAVA 输入输出程序开发
参考: java中 静态方法和非静态方法的区别 字符流的输入和输出 java文件创建.删除.读取.写入操作大全 Java键盘输入并且写入文件 File类的isDiretory Java统计子串在字符串 ...
- 每天一个linux命令:cp(8)
cp cp命令用来将一个或多个源文件或者目录复制到指定的目的文件或目录.它可以将单个源文件复制成一个指定文件名的具体的文件或一个已经存在的目录下.cp命令还支持同时复制多个文件,当一次复制多个文件时, ...
- 工厂方法配置bean
1:静态工厂方法配置bean 1):对象 package com.spring.helloworld; public class Car { private String name; private ...
- 函数————count
count和count_if函数是计数函数,先来看一下count函数:count函数的功能是:统计容器中等于value元素的个数. count(first,last,value); first是容器的 ...
- android.os.NetworkOnMainThreadException异常 (转)
转:http://blog.csdn.net/wotoumingzxy/article/details/7797295 这个异常大概意思是在主线程访问网络时出的异常. Android在4.0之前的版本 ...
- java sigar 系统监控
<dependency> <groupId>org</groupId> <artifactId>sigar</artifactId> < ...
- HTML-参考手册: 元素和有效 DOCTYPES
ylbtech-HTML-参考手册: 元素和有效 DOCTYPES 1.返回顶部 1. HTML 元素和有效 DOCTYPES HTML 元素 - 有效 DOCTYPES 下面的表格列出了所有的 HT ...