Codeforces 862D. Mahmoud and Ehab and the binary string 【二分】(交互)
<题目链接>
题目大意:
有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的 Hamming distance ,现在要求你按照步骤进行交互式操作,最终得到任意一个0、1的下标。
解题分析:
因为原串中至少存在一个0和一个1,所以一定存在一个01或者10序列,因此我们可以用二分来寻找这个序列(注意二分过程中选择区间的操作)。二分之后,一定能够得到01或10序列,然后将其按先0后1的顺序输出即可。
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; int main(){
ios::sync_with_stdio(false);
int n,num;cin>>n;
puts("?");
for(int i=;i<=n;i++)cout<<"";
puts("");
cin>>num; //第一次交互,先得到序列中1的个数
int l=,r=n;
while(r-l>=){ //二分寻找01或10串
int mid=(l+r)>>;
puts("?");
for(int i=;i<=n;i++){ //这里的区间判定方法很难想
if(i>=l && i<=mid)cout<<"";
else cout<<"";
}puts("");
int x1;cin>>x1;
if(abs(num-x1)==(mid-l+))l=mid; //判断左区间是否全为0或全为1,因为我们需要查找的是01串,所以需要向含有01串的地方收敛
else r=mid;
}
//得到了10或01串的位置后,判断其中0、1的位置
puts("?");
for(int i=;i<=n;i++){
if(i==l)cout<<"";
else cout<<"";
}puts("");
int x2;cin>>x2;
if(x2<num) printf("! %d %d\n",r,l); //先输出0的位置
else printf("! %d %d\n",l,r);
}
2019-02-01
Codeforces 862D. Mahmoud and Ehab and the binary string 【二分】(交互)的更多相关文章
- Codeforces 862D. Mahmoud and Ehab and the binary string (二分)
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...
- Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)
题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...
- codeforces D. Mahmoud and Ehab and the binary string(二分)
题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...
- D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...
- 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string
题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...
- codeforces E. Mahmoud and Ehab and the function(二分+思维)
题目链接:http://codeforces.com/contest/862/problem/E 题解:水题显然利用前缀和考虑一下然后就是二分b的和与-ans_a最近的数(ans_a表示a的前缀和(奇 ...
- Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...
- Codeforces 862A Mahmoud and Ehab and the MEX
传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
随机推荐
- IOS UINavigationController 更改返回按钮
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom]; back.titleLabel.font = [UIFont boldSy ...
- Confluence 6 使用 Apache 和 mod_proxy 的基本配置
在这些示例中,我们使用下面的信息: http://www.example.com/confluence - 你计划使用的 URL http://example:8090/ - Confluence 当 ...
- J2SE基础小结
1. 九种基本数据类型的大小,以及他们的封装类. 类型 基本类型 大小(字节) 默认值 封装类 整数型 byte 1 (byte)0 Byte short 2 (short)0 Short int 4 ...
- 最长上升子序列(dp)
链接:https://www.nowcoder.com/questionTerminal/d83721575bd4418eae76c916483493de来源:牛客网 广场上站着一支队伍,她们是来自全 ...
- Python中什么是深拷贝和浅拷贝且有什么区别
浅拷贝: >>> a = [1, 2, 3] >>> b = a >>> a [1, 2, 3] >>> b [1, 2, 3] ...
- Pycharm同步本地代码至GitHub
注册github账号 github地址,进入注册账号 安装git Windows下载地址1 Windows下载地址2 在官方下载完后,双击exe文件进行安装,安装到Windows Explorer i ...
- Docker快速部署gitlab
环境: Centos7.5 安装Docker 1.移除旧版本: $ sudo yum remove docker \ docker-client \ docker-client-latest \ do ...
- .tar.xz文件的解压方法
废话不多说: 直接看 方法一: tar -xvJf ***.tar.gz 方法二: 先减压成 .tar 格式的文件, 再解压 .tar #xz是一个工具, 系统中没有安装,需要下载 xz -d *** ...
- selenium 操作键盘
send_keys(Keys.ENTER) 按下回车键send_keys(Keys.TAB) 按下Tab制表键send_keys(Keys.SPACE) 按下空格键spacesend_keys(Kye ...
- txt提取相同内容、不同内容
findstr >相同部分.txt findstr >%~n2多余部分.txt findstr >%~n1多余部分.txt