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 ...
随机推荐
- apache安装zip包安装(非exe)
安装步骤如下: (1) 下载apache安装程序 进入官网:选择一个版本的apache 选择红色区域的内容,在之后进入的页面中: 选择红色区域的内容,进入页面: 现则VC9的进行下载. (2) 安装 ...
- 【React踩坑记二】react项目实现JS路由跳转
这里使用的是4.31版本的react-router-dom "react-router-dom": "^4.3.1", 直接使用以下代码即可实现路由跳转 thi ...
- k8s学习02-----kubeadm部署k8s
机器规划 系统配置 三台机器都执行 1.关闭selinux及firewalld sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux ...
- eclipse解决properties文件中文乱码(两种方试)
第一种:大多数网上搜到的情况(不靠谱) 第一步:windows-->properties-->General-->Content Types-->text(如下图) 第二步:p ...
- 从MYSQL的ibtmp1文件太大说起
1. 啥情况呀 测试环境机器磁盘空间不足的告警打破了下午的沉寂,一群人开始忙活着删数据.但是,不久前刚清理了一波数据,测试环境在没做压测的情况下不至于短短一个月不到就涨了200G数据,于是,我悄悄的 ...
- 《深入理解Java虚拟机》- Java虚拟机是如何加载Java类的?
Java虚拟机是如何加载Java类的? 这个问题也就是面试常问到的Java类加载机制.在年初面试百战之后,菜鸟喜鹊也是能把这流程倒背如流啊!但是,也只是字面上的背诵,根本就是像上学时背书考试一样. ...
- JMeter的JavaRequest探究
1.背景 最近笔者的一位老朋友咨询了一个问题:在自定义的Java请求中如何编写多个请求?老朋友反应他们发送请求只能基于这种Java请求形式(代码调需用三方封装的jar包).这个问题恰巧不久前在笔者所在 ...
- Spring Cloud Gateway 服务网关快速上手
Spring Cloud Gateway 服务网关 API 主流网关有NGINX.ZUUL.Spring Cloud Gateway.Linkerd等:Spring Cloud Gateway构建于 ...
- Flask框架(二)—— 反向解析、配置信息、路由系统、模板、请求响应、闪现、session
Flask框架(二)—— 反向解析.配置信息.路由系统.模板.请求响应.闪现.session 目录 反向解析.配置信息.路由系统.模板.请求响应.闪现.session 一.反向解析 1.什么是反向解析 ...
- C#/Java 动态生成电子发票
电子发票是电商时代的产物,PDF发票是最常见的电子发票之一.在这篇文章中,我将给大家分享一个免费的动态生成PDF电子发票的C#方案,并在文章末尾附上Java解决方案. 典型的发票包含客户和供应商的名称 ...