<题目链接>

题目大意:

有一个长度为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 【二分】(交互)的更多相关文章

  1. Codeforces 862D. Mahmoud and Ehab and the binary string (二分)

    题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...

  2. Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)

    题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...

  3. codeforces D. Mahmoud and Ehab and the binary string(二分)

    题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...

  4. D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...

  5. 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string

    题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...

  6. codeforces E. Mahmoud and Ehab and the function(二分+思维)

    题目链接:http://codeforces.com/contest/862/problem/E 题解:水题显然利用前缀和考虑一下然后就是二分b的和与-ans_a最近的数(ans_a表示a的前缀和(奇 ...

  7. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  8. 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 ...

  9. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

随机推荐

  1. ssh 登录报错 packet_write_wait: Connection to x.x.x.x port 22: Broken pipe

    问题 更新个人博客文章时遇到:Error: packet_write_wait: Connection to 192.30.253.113 port 22: Broken pipe packet_wr ...

  2. 洛谷P2014 选课

    首先分析题目,这是一道树形dp的题目,是树形背包类的问题,以为每门课的先修课只有一门,所以这一定可以 构成一个森林结构,于是我们可以设计一个虚拟的根节点作为森林的根. 状态转移方程如下 dp[v][k ...

  3. TypeError: $(…).tooltip is not a function

    问题描述:改了一个页面,发现进入这个页面的时候就一直在load···,F12看了一下,发现报了这个错误TypeError: $(…).tooltip is not a function,然后我就百度了 ...

  4. name

    问题 A: name 时间限制: 1 Sec  内存限制: 256 MB 题目描述 lpq同学最近突然对外国人的名字产生了兴趣,特别是外国女生的名字,于是他开始试图去认识一些国外的女生. 随着认识的女 ...

  5. angular-cli ng build 打包完成后 打开文件显示空白

    将index.html 里面的<base href="/"> 改为<base href="./"> 前面加一个 点 就好了,然后再次打包 ...

  6. Senparc.Weixin微信开发(3) 自定义菜单与获取用户组

    自定义菜单 代码参考:http://www.cnblogs.com/szw/p/3750517.html 还可以使用他们官网的自定义:https://neuchar.senparc.com/User/ ...

  7. Visual Studio 2017离线安装失败:安装程序清单签名验证失败

    解决办法: 方法1:运行gpeidit.msc,然后  Windows 设置-安全设置->本地策略-安全选项-系统机密->将FIPS兼容算法用于加密.哈希和签名-设置禁用 方法2:删除vs ...

  8. openresty capture

    local args = {} args["name"] = "张三" args["sex"] = "男" local ...

  9. adb devices unauthorized解决办法

    进行Android项目调试时,连接完设备,进行adb install ******.apk时,偶遇 adb devices unauthorized 这个小东西,解决办法:将手机设置->辅助功能 ...

  10. alpha冲刺7/10

    目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:冲刺7 团队部分 后敬甲(组长) 过去两天完成了哪些任务 界面设计.图标设计 写博客 接下来的计划 准备下周答辩 跟进进 ...