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 ...
随机推荐
- 转:ClickOnce部署Winform程序的方方面面
1. ClickOnce简介 微软官方对ClickOnce的解释是:ClickOnce 是一项部署技术,您可以利用这项技术来创建基于 Windows 的自行更新的应用程序,并且安装和运行这类应用程序所 ...
- Linux 系统的/var目录
/var目录主要针对常态性变动的文件,包括缓存(cache).登录档(log file)以及某些软件运作所产生的文件 /var目录下的重要目录 目录 应放置文件内容 /var/cache/ 应用程序本 ...
- 【JS】#001 JS定义对象写法(原型、JSON方式)
下面主要写两种 JS 定义对象的 常用写法 写法1:[很像面向对象语言中的写法] function zhongxia(age) { this.age = age; } zhongxia.name = ...
- 团队作业—预则立&&他山之石(改)
首先特别感谢刘乾学长腾出他宝贵的时间接受我的采访,为我们提出宝贵的建议,深表感谢. 1.他山之石,可以攻玉.借鉴前人的经验可以使我们减少很多走弯路的地方,这也是本次采访的目的,参考历届学长的经验,让我 ...
- SQL触发器与CLR的使用
在数据库的日常操作中,面对复杂业务的情况下,总会有用sql语句或存储过程不是那么方便的时候,所以这时候就会想到在数据库中调用CLR,也就是调用程序集,此处用C#实现来讲解一个测试案例 测试案例的业务是 ...
- 【bzoj 2839】集合计数
权限题 根据广义容斥的套路就很好做了 设\(g_i\)表示交集至少有\(i\)个元素,\(f_i\)表示交集恰好有\(i\)个元素 显然有 \[g_i=\sum_{j=i}^n\binom{j}{i} ...
- Odoo图片如何显示
转载请注明原文地址:https://www.cnblogs.com/cnodoo/p/9281423.html odoo没有专门的图片标签,但是可以通过widget来控制field标签来显示图片内容. ...
- mysql 去除特殊字符和前后空白字符
mysql 去除特殊字符 update table set field = replace(replace(replace(field,char(9),''),char(10),''),char(13 ...
- jQuery文字“橡皮圈“特效
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 10、Android--技巧
10.1.全局获取Context的技巧 在实践中有很多的地方都可以使用到Context 弹出Toast的时候需要,启动活动的时候需要.发送广播的时候需要. 操作数据库的时候需要.使用通知的时候需要.. ...