http://codeforces.com/contest/862/problem/D

交互题

fflush(stdout)

调试:

先行给出结果,函数代替输入

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define E 2.7182818284
const ll mod=1e9+;//
const int maxn=1e3+; char str[maxn];
int pos[],s,t,len=inf,x,y;
char result[maxn]="01\0";
int nn=; int cal()
{
int i,v=;
for (i=;i<=nn;i++)
if (str[i]!=result[i-])
v++;
return v;
} //'l'-'r' must have num
void work(int l,int r,int num)
{
if (l==r)
{
pos[num]=l;
return;
} int i,m=(l+r)>>;
for (i=l;i<=m;i++)
str[i]=((str[i]-) ^ )+;
printf("? %s\n",str+);
fflush(stdout);
scanf("%d",&x);
// x=cal(); for (i=l;i<=m;i++)
str[i]=((str[i]-) ^ )+; if (y-x==m-l+)
{
pos[num]=l;
return;
}
else
{
if (m-l+<len)
{
len=m-l+;
s=l;
t=m;
}
} if (x-y!=m-l+)
work(l,m,num);
else
work(m+,r,num);
} int main()
{
int n,i;
scanf("%d",&n); for (i=;i<=n;i++)
str[i]='';
str[n+]='\0';
printf("? %s\n",str+);
fflush(stdout);
scanf("%d",&y);
// y=cal();
work(,n,); if (len>)
{
for (i=;i<=n;i++)
str[i]='';
str[n+]='\0';
printf("? %s\n",str+);
fflush(stdout);
scanf("%d",&y);
// y=cal();
if (len==inf)
s=,t=n;
work(s,t,);
} printf("! %d %d",pos[],pos[]);
return ;
}

D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)的更多相关文章

  1. Codeforces 862D. Mahmoud and Ehab and the binary string (二分)

    题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...

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

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

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

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

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

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

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

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

  6. E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/E 二分答案 一个数与数组中的哪个数最接近: 先对数组中的数排序,然后lower_bound #include &l ...

  7. 【构造】【分类讨论】Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor

    题意:给你n,x,均不超过10^5,让你构造一个无重复元素的n个元素的非负整数集合(每个元素不超过10^6),使得它们的Xor和恰好为x. 如果x不为0: 随便在x里面找一个非零位,然后固定该位为0, ...

  8. 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 让x没有出现,以及0..x-1都出现就可以了. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/std ...

  9. 【Codeforces Round #435 (Div. 2) B】Mahmoud and Ehab and the bipartiteness

    [链接]h在这里写链接 [题意] 让你在一棵树上,加入尽可能多的边. 使得这棵树依然是一张二分图. [题解] 让每个节点的度数,都变成二分图的对方集合中的点的个数就好. [错的次数] 0 [反思] 在 ...

随机推荐

  1. Mysql报错型注入总结

    Mysql注入虽然是老生常谈的问题,但是工作中更多的是使用sqlmap等工具进行注入测试的,原理方面还是不是很清楚,所以这段时间主要是自己搭建环境在学手工注入,简单的将自己的学习做一个总结和记录.在常 ...

  2. python3使用csv包,读写csv文件

    python操作csv,现在很多都用pandas包了,不过python还是有一个原始的包可以直接操作csv,或者excel的,下面举个例子说明csv读写csv文件的方法: import os impo ...

  3. telnet命令详解

    基础命令学习目录 原文链接:https://www.cnblogs.com/PatrickLiu/p/8556762.html telnet命令用于登录远程主机,对远程主机进行管理.telnet因为采 ...

  4. web14 validation.xml配置 登录验证文件配置

    电影网站:www.aikan66.com 项目网站:www.aikan66.com 游戏网站:www.aikan66.com 图片网站:www.aikan66.com 书籍网站:www.aikan66 ...

  5. Task2 四则运算2

    1.任务要求:对之前的自动出题系统提出了新的要求:(1).题目避免重复:(2).可定制(数量/打印方式):(3)可以控制下列参数:是否有乘除法.数值范围.加减有无负数.除法有无余数.是否支持分数... ...

  6. java对文件的操作

    1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 public class ReadFromFile {     /**      * 以字节为单位读取文件,常用 ...

  7. Docker基础教程

    一.Docker是什么? KVM, Virtualbox, Vmware是虚拟出机器,让每个实例看到一个单独的机器:而Docker是虚拟出操作系统,实现应用之间的隔离,让各个应用觉得自己有一个自己的操 ...

  8. 10.13课堂Scrum站立会议

    项目名称:C#实现的连连看游戏 小组名称:计信F4 开会时间 :2016年10月11日 20:20~20:40 组长:张政 成员:张金生,武志远,李泉 内容: 昨日已完成: 张政:构建基础逻辑,实现游 ...

  9. TiDB注意事项

    公司最近在上测试的TiDB集群,这款数据库类似MySQL,但又不完全一致,在使用的时候有一下注意事项,在这里记录一下.

  10. Python基础:Python函数、文件操作、递归

    函数参数 函数参数包括位置参数,关键字参数,动态参数(*args, **args)三种. 传参的过程是形式参数的赋值. *args传入的参数是元组形式,**args传入的参数是字典形式. 示例代码如下 ...