【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string
题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数)。最后要你找到任意一个0的位置和任意一个1的位置。
先问n个0,返回你的原串中是1的数量,记为X。然后将任意一位改成1,倘若答案增量为1,那么你改动的那位在原串中是0,反之,那位是1。
不失一般性地,我们假设你改动的那一位在原串中是0,你就要去找1的位置。
就不断二分缩小区间,每次将当前区间划分成左右两部分l,m m+1,r。如果左半区间存在1,就去查左区间,否则去查右区间。
一个区间[L,R]没有1的充要条件是,询问0...01...10...0,中间的1恰好对应[L,R]区间,则返回的答案Y减去X恰好等于R-L+1;反之有1。
#include<cstdio>
using namespace std;
int n,x,y,pos[2];
int main(){
scanf("%d",&n);
printf("? ");
for(int i=1;i<=n;++i){
putchar('0');
}
puts("");
fflush(stdout);
scanf("%d",&x);
printf("? ");
putchar('1');
for(int i=2;i<=n;++i){
putchar('0');
}
puts("");
fflush(stdout);
scanf("%d",&y);
if(y==x+1){
pos[0]=1;
int l=1,r=n;
while(r-l>0){
int m=(l+r>>1);
printf("? ");
for(int i=1;i<l;++i){
putchar('0');
}
for(int i=l;i<=m;++i){
putchar('1');
}
for(int i=m+1;i<=n;++i){
putchar('0');
}
puts("");
fflush(stdout);
scanf("%d",&y);
if(y-x!=m-l+1){
r=m;
}
else{
l=m+1;
}
}
pos[1]=l;
printf("! %d %d\n",pos[0],pos[1]);
}
else{
pos[1]=1;
int l=1,r=n;
while(r-l>0){
int m=(l+r>>1);
printf("? ");
for(int i=1;i<l;++i){
putchar('0');
}
for(int i=l;i<=m;++i){
putchar('1');
}
for(int i=m+1;i<=n;++i){
putchar('0');
}
puts("");
fflush(stdout);
scanf("%d",&y);
if(x-y!=m-l+1){
r=m;
}
else{
l=m+1;
}
}
pos[0]=l;
printf("! %d %d\n",pos[0],pos[1]);
}
return 0;
}
【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string的更多相关文章
- 【构造】【分类讨论】Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor
题意:给你n,x,均不超过10^5,让你构造一个无重复元素的n个元素的非负整数集合(每个元素不超过10^6),使得它们的Xor和恰好为x. 如果x不为0: 随便在x里面找一个非零位,然后固定该位为0, ...
- Codeforces Round #435 (Div. 2)【A、B、C、D】
//在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...
- 【Codeforces Round #435 (Div. 2) A B C D】
CF比赛题目地址:http://codeforces.com/contest/862 A. Mahmoud and Ehab and the MEX ·英文题,述大意: 输入n,x(n,x& ...
- Codeforces 862D. Mahmoud and Ehab and the binary string (二分)
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...
- Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary 并查集
D. Mahmoud and a Dictionary 题目连接: http://codeforces.com/contest/766/problem/D Description Mahmoud wa ...
- Codeforces Round #396 (Div. 2) D. Mahmoud and a Dictionary
地址:http://codeforces.com/contest/766/problem/D 题目: D. Mahmoud and a Dictionary time limit per test 4 ...
- Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip dfs 按位考虑
E. Mahmoud and a xor trip 题目连接: http://codeforces.com/contest/766/problem/E Description Mahmoud and ...
- Codeforces Round #396 (Div. 2) A. Mahmoud and Longest Uncommon Subsequence 水题
A. Mahmoud and Longest Uncommon Subsequence 题目连接: http://codeforces.com/contest/766/problem/A Descri ...
- Codeforces Round #435 (Div. 2)
A. Mahmoud and Ehab and the MEX 题目链接:http://codeforces.com/contest/862/problem/A 题目意思:现在一个数列中有n个数,每个 ...
随机推荐
- Python3.3.3 安装(Linux系统)
1.wget http://www.python.org/ftp/python/3.3.3/Python-3.3.3.tgz //检查http://www.python.org/ftp/python网 ...
- CTSC/APIO2018 帝都一周游
day0 报道 上午早早就起来了,两点才到酒店,然后去简单试了试机子. 不得不说今年八十中的伙食变得瓜皮了啊,去年还是大叠的5元卷,今年变成了单张的*餐卷.不知道食堂吝啬什么,面条米饭都只有一点点,还 ...
- Vue基本指令
模板对象 vue指令 一:模板对象 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- MACACA===gradle下载和安装
gradle下载地址: http://services.gradle.org/distributions/ 或者直接点击这个: http://services.gradle.org/distribut ...
- MSCL超级工具类(C#),开发人员必备,开发利器
MSCL超强工具类库 是基于C#开发的超强工具类集合,涵盖了日常B/S或C/S开发的诸多方面,包含上百个常用封装类(数据库操作类全面支持Mysql.Access.Oracle.Sqlserver.Sq ...
- SQL利用Case When Then多条件判断SQL 语句
http://www.cnblogs.com/kevin2013/archive/2010/07/02/1769682.html SQL利用Case When Then多条件判断SQL ,用于sele ...
- IE7下面iframe滚动条无法用鼠标轮滚 其他浏览器可以
1.让 IFRAME 隐藏滚动条,通常的做法就是在嵌入 IFRAME 的页面的 CSS 中指定以下规则: html, body {overflow: hidden} 2.如果只是想隐藏横向滚 ...
- WdatePicker做出onchange效果
WdatePicker({onpicking: function (dp) {if (dp.cal.getDateStr() != dp.cal.getNewDateStr()) { Func(dp. ...
- HDU 4768: Flyer
题意: 有N个社团,每个社团三个属性A,B,C,表示会向编号A+k*C的同学发传单(k=0,1,2... && A+k*C <= B).题目保证最多有一个人收到的传单数是奇数. ...
- Python Flask 配置文件
1. 什么是配置文件? 就是当程序调用的一些参数,文件路径,方法或者类放到一个文件中, 当下次需要修改的一个参数的时候,不用再从所有关联的程序中找到该参数挨个修改, 比较繁琐.像Django中,程序启 ...