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 ... 
随机推荐
- 企业级实时数据文件同步服务_【all】
			全网数据定时备份方案[cron + rsync] [更多参考]全网数据定时备份方案[cron + rsync] 全网数据实时备份方案[inotify,sersync] [更多参考]全网数据实时备份方案 ... 
- 面对对象程序设计_task2_1001.A+B Format (20)
			Someting about 1001.A+B Format (20) 问题描述及我所写的代码:click here → My Task 看到这个题目的时候,我的想法很简单,直接判断直接输出,因为给定 ... 
- Django template 过滤器
			转载自: http://www.lidongkui.com/django-template-filter-table 一.形式:小写 {{ name | lower }} 二.过滤器是可以嵌套的,字符 ... 
- 1.2 Why Python for Data Analysis(为什么使用Python做数据分析)
			1.2 Why Python for Data Analysis?(为什么使用Python做数据分析) 这节我就不进行过多介绍了,Python近几年的发展势头是有目共睹的,尤其是在科学计算,数据处理, ... 
- 【bzoj 3252】攻略
			题意 我们想到一个贪心,就是每次找到根路径前缀和最大的一个点,取走这条路径,同时把这条路径上的点权变成\(0\) 正确性显然 进一步发现我们需要从树上选择\(m\)条链使得链的总和最大 于是我们考虑换 ... 
- Centos7配置samba
			Centos7配置samba 1.安装 yum install samba samba-client samba-common -y 2.配置 备份已有配置mv /etc/samba/smb.conf ... 
- Spring Cloud Eureka 学习记录
			SpringCloud版本 <groupId>org.springframework.cloud</groupId> <artifactId>spring-clou ... 
- js之radio应用实例
			radio和checkbox还有select,可谓是前后端常用三剑客啊!特别是checkbox和select,关于这两个今天不讲,因为在下面这几篇文章,我已经比较详细的讲解了. SpringMVC之a ... 
- P1437 [HNOI2004]敲砖块
			题目描述 在一个凹槽中放置了 n 层砖块.最上面的一层有n 块砖,从上到下每层依次减少一块砖.每块砖 都有一个分值,敲掉这块砖就能得到相应的分值,如下图所示. 14 15 4 3 23 33 33 7 ... 
- openstack placement 组件作用理解
			例如,一个资源提供者可以是一个计算节点,共享存储池,或一个IP分配池.placement服务跟踪每个供应商的库存和使用情况.例如,在一个计算节点创建一个实例的可消费资源如计算节点的资源提供者的CPU和 ... 
