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+ ...
随机推荐
- Hadoop生态圈-Kafka的旧API实现生产者-消费者
Hadoop生态圈-Kafka的旧API实现生产者-消费者 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.旧API实现生产者-消费者 1>.开启kafka集群 [yinz ...
- JAVA-Servlet高级应用
会话只是指一段指定的时间间隔. 会话跟踪是维护用户状态(数据)的一种方式.它也被称为servlet中的会话管理. Http协议是一个无状态的,所以我们需要使用会话跟踪技术来维护用户状态. 每次用户请求 ...
- bzoj千题计划198:bzoj1084: [SCOI2005]最大子矩阵
http://www.lydsy.com/JudgeOnline/problem.php?id=1084 m=1: dp[i][j] 前i个数,选了j个矩阵的最大和 第i个不选:由dp[i-1][j] ...
- Maven 环境的配置
Maven 环境的配置 现在Java新架构的不断出现,例如Struts,Spring,Hibernate等,项目的配置文件的增多,给开发人员带来很大麻烦.在实际的开发当中,Myeclipse中的pro ...
- 01 uni-app框架学习:项目创建及底部导航栏tabBar配置
1.创建一个项目类型选择uniapp 2. pages里新建3个页面如下 3.在pages.json中配置底部导航tabBar 效果展示:
- linux sftp安装【转】
工具:虚拟机:VMware Workstation Pro.操作系统:CentOS-6.4-x86_64-minimal.终端模拟器:Xshell 5 .ftp:filezilla 一.让虚拟机联网 ...
- 002_分布式搜索引擎Elasticsearch的查询与过滤
一.写入 先来一个简单的官方例子,插入的参数为-XPUT,插入一条记录. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 curl -XPUT 'http:/ ...
- Java类的继承与多态特性-入门笔记
相信对于继承和多态的概念性我就不在怎么解释啦!不管你是.Net还是Java面向对象编程都是比不缺少一堂课~~Net如此Java亦也有同样的思想成分包含其中. 继承,多态,封装是Java面向对象的3大特 ...
- SSL邮件发送(腾讯企业邮箱测试通过,可以支持多附件)
参考网址:http://www.cnblogs.com/LUA123/p/5575134.html ,谢谢! package net.common.utils.common; import java. ...
- easyui tree:根据属性格式化树节点名称
$('#resourceTree').tree({ method : 'post', animate : true, onContextMenu : function(e, node) { e.pre ...