题目链接

\(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(交互 二分)的更多相关文章

  1. Codeforces 862D. Mahmoud and Ehab and the binary string 【二分】(交互)

    <题目链接> 题目大意: 有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的   Hamming ...

  2. Codeforces 862D. Mahmoud and Ehab and the binary string (二分)

    题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...

  3. codeforces D. Mahmoud and Ehab and the binary string(二分)

    题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...

  4. D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...

  5. 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string

    题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...

  6. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  7. 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 ...

  8. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  9. Codeforces 862B - Mahmoud and Ehab and the bipartiteness

    862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...

随机推荐

  1. CCNA学习与实验指南——第3章 以太网

    以太网就是局域网,IEEE制定了802.2和802.3两种标准.802.2规定了OSI模型的数据链路层的上半部分(LLC子层),802.3规定了OSI模型的数据链路层的下半部分和物理层(MAC子层). ...

  2. python---django中url访问方法

    只是了解,不推荐使用,毕竟干扰太多,任意冲突,也没有解耦,应该使用路由分发 在url匹配中支持正则匹配,例如: from django.conf.urls import include, urlfro ...

  3. Mysql select id 加上order by 后结果不一致

    测试数据将近280万 1.SELECT id FROM cbbd ORDER BY id LIMIT 900000,10 2.SELECT id FROM cbbd  LIMIT 900000,10 ...

  4. 【原创】backbone1.1.0源码解析之Collection

    晚上躺在床上,继续完成对Backbone.Collection的源码解析. 首先讲讲它用来干嘛? Backbone.Collection的实例表示一个集合,是很多model组成的,如果用model比喻 ...

  5. html5 canvas显示文字(写上5个字,纪念我那刚刚逝去的爱情)

    <script type="text/javascript"> window.addEventListener('load',eventWindowLoaded,fal ...

  6. Saving Tang Monk II

    题目链接:http://hihocoder.com/contest/acmicpc2018beijingonline/problem/1 AC代码: #include<bits/stdc++.h ...

  7. parallelogram

    The parallelogram law in inner product spaces Vectors involved in the parallelogram law. In a normed ...

  8. python psutil监控系统资源【转】

    通过 运用 Python 第三方 系统 基础 模块, 可以 轻松 获取 服务 关键 运营 指标 数据,包括 Linux 基本 性能. 块 设备. 网卡 接口. 系统 信息. 网络 地址 库 等 信息. ...

  9. linux服务器如何添加sudo用户

    1. 编辑 vi /etc/ssh/sshd_config 文件,修改默认端口:默认Port为22,并且已经注释掉了,修改是把注释去掉,并修改成其它的端口. 原来用默认端口:22修改为:8975 (这 ...

  10. C++的那些事 1

    最近在看c++的一些库文件,里面的一些比较陌生但看起来挺有用的一些东西,在此记下,以免日后看到再翻找资料. template <size_t _Nb> 这是在看bitset的时候看到的,之 ...