<题目链接>

题目大意:

有一个长度为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. Centos 7.3下 Linux For SQL Server安装及配置介绍

    Centos 7.3下 Linux For SQL Server安装及配置介绍 高文龙关注13人评论2828人阅读2017-03-05 21:46:21 Centos 7.3下Linux For SQ ...

  2. UserNotifications ios10 通知使用

    通知在ios10 中推荐使用 导入  import UserNotifications  头文件 if #available(iOS 10.0, *) { UNUserNotificationCent ...

  3. PHP 命名空间与自动加载机制

    include 和 require 是PHP中引入文件的两个基本方法.在小规模开发中直接使用 include 和 require 没哟什么不妥,但在大型项目中会造成大量的 include 和 requ ...

  4. Max Sum (dp)

    Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. F ...

  5. 单例、异常、eval函数

    一.单例 01. 单例设计模式 设计模式 设计模式 是 前人工作的总结和提炼,通常,被人们广泛流传的设计模式都是针对 某一特定问题 的成熟的解决方案 使用 设计模式 是为了可重用代码.让代码更容易被他 ...

  6. cf441 f组合数。。单调指针

    e没学过做不出来.. 处理合法的区间很麻烦,但是处理非合法的区间很容易 答案就是所有的取法-不合法的区间 这题一定要双边界推进处理!!!! 一开始用单边界向右推进,结果后来发现错了,拿样例1就可以证明 ...

  7. 解决Xshell不从22端口连接服务器

    xshell默认是22端口 如果服务器给的ssh端口不是22,会连接失败 需要去指定连接 新建 设置ip和端口,点下面的确定 双击刚创建的会话 输入用户名密码 连接成功

  8. Allegro PCB Design GXL (legacy) 使用slide无法将走线推挤到焊盘的原因

    Allegro PCB Design GXL (legacy) version 16.6-2015 启用slide命令之后,单击鼠标右键,取消“Enhanced Pad Entry”即可.

  9. Axure实现多用户注册验证

    *****多用户登录验证***** 一.(常规想法)方法:工作量较大,做起来繁琐 1.当用户名和密码相同时怎么区分两者,使用冒号和括号来区分: eg. (admin:123456)(123456:de ...

  10. python发送邮件(在邮件中显示HTMLTestRunner生成的报告)

    import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart f ...