题目链接:http://codeforces.com/contest/862/submission/30696399

题解:这题一看操作数就知道是二分答案了。然后就是怎么个二分法,有两种思路第一种是找两遍第一遍找1第二遍找0但是这样肯定超时所以还不如直接找相邻的01串或者10串具体查找方法是先将所有串赋值为0这样就能得到1的总个数,然后将所要求的区间全赋值为1其他赋值为0。设num1为总的1的个数反馈的值其实就是表示L~R之间0的个数,然后只要满足(设返回的数为now)只要满足num1-now<(R-L+1)&&num1-now>-(R-L+1)就二分到这个区间因为这个区间能够确保既有0又有1然后知道L与R就相差1就行,之后确定0,1位置就简单了就是在L,R两个位置里找,还有题目要求的flush一下

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
string s;
int now , num1 , n;
bool check(int L , int R) {
cout << "? ";
for(int i = ; i < L ; i++) putchar('');
for(int i = L ; i <= R ; i++) putchar('');
for(int i = R + ; i < n ; i++) putchar('');
puts("");
fflush(stdout);
cin >> now;
if(num1 - now > -(R - L + ) && num1 - now < (R - L + )) return true;
else return false;
}
int main() {
cin >> n;
cout << "? ";
for(int i = ; i < n ; i++) {
putchar('');
}
puts("");
fflush(stdout);
cin >> num1;
int L = , R = n - ;
while(R - L > ) {
int mid = (L + R) >> ;
if(check(mid , R)) {
L = mid;
}
else {
R = mid;
}
}
cout << "? ";
for(int i = ; i < L ; i++) putchar('');
for(int i = L ; i < R ; i++) putchar('');
for(int i = R ; i < n ; i++) putchar('');
puts("");
fflush(stdout);
cin >> now;
if(now > num1) {
cout << "! " << L + << ' ' << R + << endl;
}
else {
cout << "! " << R + << ' ' << L + << endl;
}
return ;
}

codeforces D. 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 【二分】(交互)

    <题目链接> 题目大意: 有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的   Hamming ...

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

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

  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. 【Android】No resource found that matches the given name 'Theme.Sherlock.Light.NoActionBar'

    被这个问题困扰了好久…… 错误如下: error: Error retrieving parent for item: No resource found that matches the given ...

  2. Linux 常见的常识及常用快捷键方式

    1.  ,请写出linux系统中常见一级目录的名称及作用. /root :   超级用户的家目录 /home:  普通用户的家目录 /boot:   启动目录,启动相关文件(系统内核启动文件) /de ...

  3. Java 性能优化(一)

    Java 性能调优(一) 1.衡量程序性能的标准 (1) 程序响应速度: (2) 内存占有情况: 2.程序调优措施 (1) 设计调优 设计调优处于所有调优手段 的上层,需要在软件开发之前进行.在软件开 ...

  4. .NET Core 3.0深入源码理解HttpClientFactory之实战

      写在前面 前面两篇文章透过源码角度,理解了HttpClientFactory的内部实现,当我们在项目中使用时,总会涉及以下几个问题: HttpClient超时处理以及重试机制 HttpClient ...

  5. HttpClientFactory 使用说明 及 对 HttpClient 的回顾和对比

    目录 HttpClient 日常使用及坑点: HttpClientFactory 优势: HttpClientFactory 使用方法: 实战用法1:常规用法 1. 在 Startup.cs 中进行注 ...

  6. java随笔之接口

    /* * 接口大致上可以分为:哑接口,抽象接口,接口类 * 哑接口:就是public,protected(注意protect有包权限,只有本包才开放接口)方法 * 抽象接口:就是哑接口变为抽象方法,在 ...

  7. java中什么是继承笔记

    继承 怎样实现继承:1,先提取共有的属性和方法,放到一个类里,这个叫父类.基类.超类        2.编写子类 修饰符 class 子类名 extends 父类名 好处:提高代码的复用性 子类怎么去 ...

  8. PDF.js 详情解说

    pdf.js资源下载 点我下载 自定义默认加载的pdf资源 在web/view.js中我们可以通过DEFAULT_URL设置默认加载的pdf.通过上面代码我们也可以看出来可以通过后缀名来指定加载的pd ...

  9. Git使用(码云)

    1.安装git软件(码云/GitHub) 2.码云注册,保存代码 3.创建代码托管仓库,仓库名相当于码云上的文件夹 4.写作业并提交 在作业文件夹上,右键选择‘get bash here’ 在黑框里输 ...

  10. SQL获取客户端网卡电脑名称等信息

    Select SYSTEM_USER 当前用户名, USER_NAME() 当前所有者,db_Name() 当前数据库,@@SPID 当前进程号,(select top 1 FileName from ...