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. Yii2 输出图片相关

    http://www.yiichina.com/doc/api/2.0/yii-web-response#$format-detail https://segmentfault.com/q/10100 ...

  2. PHP正则表达式匹配俄文字符

    之前弄过匹配中文的 见 http://www.cnblogs.com/toumingbai/p/4688433.html preg_match_all("/([\x{0400}-\x{04F ...

  3. shell之arp命令

    arp: 显示所有的表项. arp -d address: 删除一个arp表项. arp -s address hw_addr: 设置一个arp表项.   常用参数: -a 使用bsd形式输出.(没有 ...

  4. Flexbox + js实现滑动拼图游戏

    滑动拼图就是把一张图片分成几等份,打乱顺序(下图),然后通过滑动拼凑成一张完整的图片. 要实现一个拼图游戏,需要考虑怎样随机的打乱顺序,怎样交换两张图片的位置,等等.但是,使用了Flexbox布局以后 ...

  5. 奔跑吧DKY——团队Scrum冲刺阶段-Day 4

    今日完成任务 谭鑫:主要解决之前存在的控件不灵敏问题,导致界面跳转不顺利. 黄宇塘:制作新的游戏背景图,对主界面图进行调整. 赵晓海:主要解决之前存在的控件不灵敏问题,导致界面跳转不顺利. 方艺雯:制 ...

  6. python接口测试之requests库(一)

    一.requests库的安装 requests库作为第三方库,需要安装 cmd模式下,运行pip install requests 二.在学习如何发送请求之前,我们先来了解一下requests库,查看 ...

  7. 索引超出了数组界限。 在 System.Collections.Generic.Dictionary`2.Resize

    博问:Dictionary 超出了数组界限 异常: Exception type: IndexOutOfRangeException Exception message: 索引超出了数组界限. 在 S ...

  8. charles抓取移动端app数据

    pc端为mac 移动端为android pc端 1.下载charles并安装 安利一个超好的良心网站(好多好用的软件都可以在上面找到,并且免费): http://xclient.info/search ...

  9. Beta阶段——4

    一.提供当天站立式会议照片一张: 二. 每个人的工作 (有work item 的ID) (1) 昨天已完成的工作: 完善了用户管理模式的功能 (2) 今天计划完成的工作: 对用户功能的添加. (3) ...

  10. 【问底】徐汉彬:PHP7和HHVM的性能之争 (真是学到了很多)

    来源:http://www.csdn.net/article/2014-12-25/2823234 作者:徐汉彬 摘要:近日,PHP7和HHVM的性能之争成为了一个讨论热点,但毫无疑问,它们都在提升P ...