题目链接: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 (二分)的更多相关文章

  1. Codeforces 862D. Mahmoud and Ehab and the binary string 【二分】(交互)

    <题目链接> 题目大意: 有一个长度为n(n<1000)的01串,该串中至少有一个0和一个1,现在由你构造出一些01串,进行询问,然后系统会给出你构造的串与原串的   Hamming ...

  2. Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)

    题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...

  3. codeforces D. Mahmoud and Ehab and the binary string(二分)

    题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...

  4. D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio ...

  5. 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string

    题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...

  6. codeforces E. Mahmoud and Ehab and the function(二分+思维)

    题目链接:http://codeforces.com/contest/862/problem/E 题解:水题显然利用前缀和考虑一下然后就是二分b的和与-ans_a最近的数(ans_a表示a的前缀和(奇 ...

  7. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  8. 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 ...

  9. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

随机推荐

  1. 使用CADisplayLink写秒表

    使用CADisplayLink写秒表 效果: 源码: StopWatch.h 与 StopWatch.m // // StopWatch.h // ShowTime // // Created by ...

  2. iOS系统声音列表

    iOS系统声音列表 效果 说明 1. 点击cell就能发出声音 2. 只需要给出声音编号,就可以,非常简单易用 源码 https://github.com/YouXianMing/iOS-Utilit ...

  3. Python学习---ModelForm拾遗180325

    ModelForm适用于前台验证和后台直接操作数据库的前后台未做分离,可以一次执行验证和保存数据的场景. 注意:  1.  ModelForm里面没有删除方法,需要手动删除内容 2. ModelFor ...

  4. 如何处理高并发情况下的DB插入

    1.  我们需要接收一个外部的订单,而这个订单号是不允许重复的 2.  数据库对外部订单号没有做唯一性约束 3.  外部经常插入相同的订单,对于已经存在的订单则拒绝处理 对于这个需求,很简单我们会用下 ...

  5. javascript库概念与连缀

    一.JavaScript 库 1.什么是javascript库: javascript库,说白了,就是把各种常用的代码片段,组织起来放在一个 js 文件里,组成一个包,这个包就是 JavaScript ...

  6. Rabbitmq.md

    RabbitMQ介绍 什么是RabbitMQ RabbitMQ是实现AMQP(高级消息队列协议)的消息中间件的一种,最初起源于金融系统,用于在分布式系统中存储转发消息,在易用性.扩展性.高可用性等方面 ...

  7. UVa 1252 - Twenty Questions(状压DP)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. 4518: [Sdoi2016]征途

    Description Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界点设有休息站. Pine计划用m天到达T地.除第m天外,每一天晚上Pine都必须在休息站过夜 ...

  9. ethereumjs/ethereumjs-common-3-test

    查看test能够让你更好滴了解其API文档的使用 ethereumjs-common/tests/chains.js const tape = require('tape') const Common ...

  10. zookeeper 集群安装与配置

    Zookeeper安装和配置 准备工作 安装 JDK,此步略. 下载 zookeeper wget http://archive.apache.org/dist/zookeeper/zookeeper ...