codeforces D. Mahmoud and Ehab and the binary string(二分)
题目链接: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(二分)的更多相关文章
- 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 【二分】(交互)
<题目链接> 题目大意: 有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的 Hamming ...
- Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)
题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...
- 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 ...
随机推荐
- 【Android】drawable VS mipmap
Android Studio 创建工程后默认的资源文件夹如下图所示: 一直有些疑惑的是 mipmap 和 drawable 文件夹有什么区别,以及是否还需要创建 drawable-xhdpi, dra ...
- 【iOS】copy 关键字
以前没注意过 iOS 的 copy, nonatomic, assign, weak, strong 等关键字. 偏偏今天遇到了一个问题,恰恰是关键字的问题,如图: 之前用的是 assign, 没有用 ...
- 【python-django后端开发】Redis缓存配置使用详细教程!!!
官方查阅资料:https://django-redis-chs.readthedocs.io/zh_CN/latest/ 1. 安装django-redis扩展包 1.安装django-redis扩展 ...
- C#:正则表达式类
Regex r = new Regex("abc"); // 定义一个Regex对象实例(Regex r = new Regex("abc", RegexOp ...
- C#下载文件,Stream 和 byte[] 之间的转换
stream byte 等各类转换 http://www.cnblogs.com/warioland/archive/2012/03/06/2381355.html using (System.Net ...
- 8、大型项目的接口自动化实践记录----DB分别获取预期结果、实际结果
上一篇实现数据分离升级版--从DB获取数据,以及对应的请求实现,作为一个case,还缺少了预期结果与实际结果的获取及对比.因为前面的文章已经说过接口返回值的获取及对比,所以这篇不说这块了,这篇说一下D ...
- 洛谷P2125 题解
吐槽: 只能说这道题很数学,本数学蒟蒻推了半天没推出来,只知道要用绝对值,幸亏教练提醒,才勉强想出正解(似乎不是这样的),真的是很无语. 以上皆为吐槽本题,可直接 跳过 分析: 既然题目是要使书架上的 ...
- 如何思考博弈dp
两个人的规则是否一致 若仅仅是先后的差别 我们可用dp解决一般思考一个子状态 对于当前的那个状态 我们进行什么样的操作 已知什么
- python3学习-requests使用
前面我们讲过了urllib模块,知道他是用于网络请求的,这一节讲的requests还是用于网络请求的,只不过urllib是官方模块,而requests是第三方的模块.用过的人都说他才是'人类使用的', ...
- idea+Spring+Mybatis+jersey+jetty构建一个简单的web项目
一.先使用idea创建一个maven项目. 二.引入jar包,修改pom.xml <dependencies> <dependency> <groupId>org. ...