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 ...
随机推荐
- 【iOS】安装 CocoaPods
1. 打开 terminal 2. 移除现有 Ruby 默认源 $ gem sources --remove https://rubygems.org/ 3. 使用新的源 $ gem sources ...
- 【iOS】libc++abi.dylib: terminate_handler unexpectedly threw an exception
用 ShareSDK 做第三方分享的时候遇到了这个问题…… 联系了客服,后来在他的指导下,发现是数组的问题,该问题不知道是否具有通用性,暂且记下.
- WPF 打开网页
1.利用浏览器打开using System.Diagnostics; Process proc = new System.Diagnostics.Process(); proc.StartInfo.F ...
- java课堂 动手动脑3
(1) 该函数没有赋初值再就是如果类提供一个自定义的构造方法,将导致系统不在提供默认的构造方法. (2) public class test { public static void main(Str ...
- C# Winform 自定义控件——竖着的Navbar
效果: 描述: 这是一个可折叠的菜单导航,主要是由panel.picturebox.label完成,界面的颜色用来区分一下各个组合控件,便于调试. 首先,首先是ImageButton: 这个是由Pic ...
- SDS模块
早上花了一点时间读了下sds的相关源码,其实sds就是构造了两个字段用来记录len和free的状态,然后还有一个char[]用来记录字符串的值. 然后sds模块的函数都是在模拟str的操作. 比较,追 ...
- JNDI----数据连接池
JNDI:提供了查找和访问各种命名和目录服务的通用,统一的接口 常用的配置属性: name:表示以后要查找的名称.通过此名称可以找到DataSource,此名称任意更换,但是程序中最终要查找的就是 ...
- 冬天苹果笔记macbookpro消除静电的方法
冬天mac除静电的方法 1.mac虽然声称不需要关机,但和apple技术人员沟通后,还是需要1周进行一次关机操作 2.知乎上的回答:https://www.zhihu.com/question/195 ...
- 关于p标签不能嵌套div标签引发的标签嵌套问题总结
问题由来:<p>中嵌套<div>标签,两个都是块级元素,按理应该可以正常显示,但是最后的结果居然是多出来一段<p>的效果,所以就在网上找了许多关于标签嵌套规则的资料 ...
- MVC+EF Core 完整教程20--tag helper详解
之前我们有一篇:“动态生成多级菜单”,对使用Html Helper做了详细讲述,并且自定义了一个菜单的 Html Helper: https://www.cnblogs.com/miro/p/5541 ...