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+ ...
随机推荐
- bzoj千题计划201:bzoj1820: [JSOI2010]Express Service 快递服务
http://www.lydsy.com/JudgeOnline/problem.php?id=1820 很容易想到dp[i][a][b][c] 到第i个收件地点,三个司机分别在a,b,c 收件地点的 ...
- c#的as,is 运算符
- 转----MarkdownPad2.5 注册码
经测试可用 User: Soar360@live.com 授权: GBPduHjWfJU1mZqcPM3BikjYKF6xKhlKIys3i1MU2eJHqWGImDHzWdD6xhMNLGVpbP2 ...
- CSS-3 box-shadow 的使用
box-shadow是给对象实现图层阴影效果的. 语法: E {box-shadow: <length> <length> <length>?<length& ...
- 经典设计模式-iOS的实现
最近看了<HeadFirst 设计模式>这本书,给组内伙伴准备一次分享,把这次分享记录下来,有需要的可以看看. 这本书主要介绍了四人帮23种经典设计模式中的的14种,也是常用的几种.看完这 ...
- UVALive 7456 Least Crucial Node
题目链接 题意: 给定一个无向图,一个汇集点,问哪一个点是最关键的,如果有多个关键点,输出序号最小的那个. 因为数据量比较小,所以暴力搜索就行,每去掉一个点,寻找和汇集点相连的还剩几个点,以此确定哪个 ...
- MongoDB 之 "$" 的奇妙用法 MongoDB - 5
在MongoDB中有一个非常神奇的符号 "$" "$" 在 update 中 加上关键字 就 变成了 修改器 其实 "$" 字符 独立出现 ...
- MySQL多源复制【转】
什么是多源复制? 首先,我们需要清楚 multi-master 与multi-source 复制不是一样的. Multi-Master 复制通常是环形复制, 你可以在任意主机上将数据复制给其他主机. ...
- 在VMware上安装Ubuntu软件步骤与遇到的相关问题及解决方案
图解演示环境版本: 本机系统: WIN10 虚拟机:VMware Workstation 12(中文版) 安装目标:Ubuntu Desktop 12.04 LTS (请点击这里)先下载好iso镜像 ...
- 通过anaconda进行python多版本控制
---恢复内容开始--- linux与windows通用. 1. 假设电脑上已经转好anaconda3. (anaconda 默认装好了python3.jupyter.spyter) 2. 现在需求是 ...