Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)
\(Description\)
有一个长为\(n\)的二进制串,保证\(01\)都存在。你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串的不同位的数目。求任意一个\(0\)和\(1\)的位置。
\(n\leq 1000\)。
\(Solution\)
通过\(0...\)和\(1...\)就可以判断出第一个数是什么。然后二分,对每个区间判断是否全为\(0/1\),就可以找到另一个了。
为啥有时候用read()会T。。
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define gc() getchar()
const int N=1005;
int n;
char s[N];
inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
inline int Query()
{
putchar('?'), puts(s); fflush(stdout);
int t; scanf("%d",&t); return t;
// return read();
}
inline void Fill(int l,int r,const char c)
{
for(int i=l; i<=r; ++i) s[i]=c;
}
int Solve(const char q,const char std)
{
for(int i=1; i<=n; ++i) s[i]=std;
int l=2,r=n,mid,bef=Query(),tmp;
while(l<r)
{
Fill(l,mid=l+r>>1,q), tmp=Query(), Fill(l,mid,std);
if(std::abs(bef-tmp)==mid-l+1 && bef>tmp) return l;//注意等于区间长度时差值可能是不变的
if(std::abs(bef-tmp)<mid-l+1) r=mid;
else l=mid+1;
}
return l;
}
int main()
{
scanf("%d",&n); //n=read();
for(int i=1; i<=n; ++i) s[i]='0'; s[0]=' ', s[n+1]='\0';
int t0=Query(); s[1]='1'; int t1=Query();
int ans0, ans1;
if(t0<t1) ans0=1, ans1=Solve('1','0');
else ans1=1, ans0=Solve('0','1');
printf("! %d %d\n",ans0,ans1);
return 0;
}
Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)的更多相关文章
- 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 (二分)
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...
- codeforces D. Mahmoud and Ehab and the binary string(二分)
题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...
- 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 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 ...
- Codeforces 862B - Mahmoud and Ehab and the bipartiteness
862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...
随机推荐
- shell jq
Mark 下,周末来补充 参考资料: https://stedolan.github.io/jq/tutorial/
- hdu 4857 Little Devil I
http://acm.hdu.edu.cn/showproblem.php?pid=4897 题意:给你一棵树,边的颜色要么为白色,要么为黑色,初始每条边为白色,有三种操作 1.将u-v链上面的所有边 ...
- 蓝桥杯 带分数 DFS应用
问题描述 100 可以表示为带分数的形式:100 = 3 + 69258 / 714. 还可以表示为:100 = 82 + 3546 / 197. 注意特征:带分数中,数字1~9分别出现且只出现一次( ...
- 20155203 2016-2017-3 《Java程序设计》第5周学习总结
20155203 2016-2017-3 <Java程序设计>第5周学习总结 教材学习内容总结 课堂知识总结 封装是继承的基础,继承是多态的基础.多态是用父类声明对象的引用,用子类生成对象 ...
- Java内存模型-final域的内存语义
一 引言 说到final你肯定知道它是Java中的关键字,那么它所在Java中的作用你知道吗?不知道的话,请前往这篇了解下https://www.cnblogs.com/yuanfy008/p/802 ...
- 让浏览器重新下载css文件,解决不刷新缓存的问题
网站页面源代码中的css文件和js文件后面带一个问号,后面跟着一连串数字或字符,问号起不到实际作用,仅能当作后缀,如果用问号加参数的方法,可以添加版本号等信息 它的作用有:1.作为版本号,让自己方便记 ...
- springcloud常见问题处理
无法在任何已知服务器上执行请求. 原因是注册中心未启动.在使用springcloud搭建微服务时,一定要先启动注册中心,再启动服务端和客户端.具体报错如下: com.netflix.discovery ...
- js如何判断一个对象是不是Array?
在开发中,我们经常需要判断某个对象是否为数组类型,在Js中检测对象类型的常见方法都有哪些呢? typeof 操作符 对于Function, String, Number ,Undefined 等几种类 ...
- angular有关网站
angular官网 https://v2.angular.cn/docs/ts/latest/ angular更新信息https://github.com/angular/angular/blob/m ...
- logback.xml 模板
ssm模板 <?xml version="1.0" encoding="UTF-8"?> <!--configuration 根节点,包含下 ...