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 ...
随机推荐
- Confluence 6 关于嵌入的 H2 数据库
你的 Confluence 安装中包含有嵌入的 H2 数据库,能够让你试用 Confluence 而不需要安装任何的外部数据库.H2 数据库仅仅用于你对 Confluence 进行评估.在你将 Con ...
- axis 数据流
产生数据流的代码 模板 重新修改了下 :]axis_data_cnt='d0; :]axis_data_frame_cnt='d0; :]delay_cnt='d0; initial begin ...
- js操作数组元素
一, 删除数组指定的某个元素 首先可以给JS的数组对象定义一个函数,用于查找指定的元素在数组中的位置,即索引,代码为: Array.prototype.indexOf = function(val) ...
- Java并发编程基础-线程安全问题及JMM(volatile)
什么情况下应该使用多线程 : 线程出现的目的是什么?解决进程中多任务的实时性问题?其实简单来说,也就是解决“阻塞”的问题,阻塞的意思就是程序运行到某个函数或过程后等待某些事件发生而暂时停止 CPU 占 ...
- <a>之间怎么放值</a> 挺简单的,第一次遇到···
需求描述:对列表中的某一列内容添加a标签(其实就是对td标签下添加a标签了). 思路简介:拿到这个我首先的反应就是在td标签对text获取内容的代码中动态拼接<a></a>字符 ...
- Wireless Penetration Testing(命令总结)
1.对本书出现的无线网络涉及的命令做一总结 查看无线网卡( Create a monitor mode interface using your card as shown in the follow ...
- MySQL5.7版本及以上,改密码sql语句;grant创建用户已经密码
mysql> update mysql.user set authentication_string = password('*****') where user = 'root'; gran ...
- 关于C++ const 的全面总结 (转)
C++中的const关键字的用法非常灵活,而使用const将大大改善程序的健壮性,本人根据各方面查到的资料进行总结如下,期望对朋友们有所帮助. Const 是C++中常用的类型修饰符,常类型是指使用类 ...
- NPOI操作Excel(一)--NPOI基础
用C#读取Excel的方法有很多中,由于近期工作需要,需要解析的Excel含有合并单元格以及背景色等特殊要求,故在网上查了一些关于读Excel的方法的优缺点,觉得NPOI能满足我的需要,所以搜索了一些 ...
- linux:安装并使用mongo
1.下载mongo: curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz 2.解压: tar -zxvf ...