Codeforces 862D. Mahmoud and Ehab and the binary string (二分)
题目链接:Mahmoud and Ehab and the binary string
题意:
一道交互题,首先给出一个字符串的长度l。现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这个字符串与目标串之间不同的字符的个数。要在15次的提问内,找到目标串中任意一个1和0的位置。
题解:
因为是15次提问,其实可以想到二分,但是分别对0和1进行二分差不多要二十多次,所以可以对01或10进行二分,查找某一个01或10串的位置。
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5+;
int vec[MAX_N];
int main()
{
int N,M,T;
cin>>N;
printf("?\n");
for(int i=;i<=N;i++) printf("");
cout<<endl;
int num;
cin>>num;
int l = ,r = N,x;
while(r-l>=)
{
int mid = (l+r)/;
printf("?\n");
for(int i=;i<=N;i++)
{
if(i>=l && i<=mid) printf("");
else printf("");
}
cout<<endl;
cin>>x;
if(abs(num - x) == mid - l + ) l = mid;
else r = mid;
}
int x1,x2;
printf("?\n");
for(int i=;i<=N;i++)
{
if(i == l) printf("");
else printf("");
}
cout<<endl;
cin>>x1;
if(x1<num)
{
printf("! %d %d\n",r,l);
}
else printf("! %d %d\n",l,r);
return ;
}
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(交互 二分)
题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...
- 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 E. Mahmoud and Ehab and the function(二分+思维)
题目链接:http://codeforces.com/contest/862/problem/E 题解:水题显然利用前缀和考虑一下然后就是二分b的和与-ans_a最近的数(ans_a表示a的前缀和(奇 ...
- 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 ...
随机推荐
- 生成器(generator),迭代器(yield)
g=(i for i in range(10)) #小括号表示生成一个迭代生成器.[]是列表生成器 g.__next__() yield将一个函数变成生成器 import time def f(): ...
- windows 下安装nodejs 要怎么设置环境变量
windows 下安装nodejs 了,也安装了npm, 但是有时候切不能直接用request(‘ws’)这一类的东西.我觉得是确实环境变量或其他设置有问题,能否给个完整的设置方案: 要设置两个东西, ...
- Ardunio控制RGB的LED灯显示彩虹渐变色.
由于我使用的是共阴极的RGB LED,如果你的是共阳极的,接线的时候要注意一下. 其他没什么不同 //定义RGB色彩的输出I/O ; ; ; //标记颜色变化的方式,增加值还是减小值 bool red ...
- Oracle SQL Developer官方工具 初探
查询表数据(打开工作表:Alt+F10) 运行SQL语句:(格式化:Ctrl+F7) 自动完成语句的设置 自动弹出的速度加快,并且将命中率提高,进行如下设置: 由于我的输入法占用了CTRL+,的快捷建 ...
- php实现简单的单链表
<?php /** * 建立一个链表,节点的data为数组,记录一个id,完成链表所以操作 */ //结点,结点数据data定义为一个数组,id和value class Node{ public ...
- 浅谈MyBatis缓存
在谈论MyBatis的缓存之前,我们先说说它的延迟加载,所谓延迟加载, resultMap中的association和collection标签具有延迟加载的功能.延迟加载的意思是说,在关联查询时,利用 ...
- Golang Http Server源码阅读
建议看这篇文章前先看一下net/http文档 http://golang.org/pkg/net/http/ net.http包里面有很多文件,都是和http协议相关的,比如设置cookie,head ...
- head头的设计:rfcn light-head rfcn
faster缺点:1.不是全卷积,roi出来后是两个fc层,这样会丧失平移变性. 2.每个roi都要单独经过两个fc层,也就是分别进行分类和回归,耗时 也有种说法是roi-pooling后导致平移 ...
- 第三方开源插件zTree的使用
zTree实现树形节点勾选效果图 使用流程: JS文件导入和引用 css文件导入和引用 demo代码 JS.css文件导入和引用 3个核心JS文件及两个核心css文件 demo相关代码: <!D ...
- 965. Univalued Binary Tree
题目来源: https://leetcode.com/problems/univalued-binary-tree/submissions/ 自我感觉难度/真实难度: 题意: 分析: 自己的代码: c ...