D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
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)的更多相关文章
- Codeforces 862D. Mahmoud and Ehab and the binary string (二分)
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...
- codeforces D. Mahmoud and Ehab and the binary string(二分)
题目链接:http://codeforces.com/contest/862/submission/30696399 题解:这题一看操作数就知道是二分答案了.然后就是怎么个二分法,有两种思路第一种是找 ...
- 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 Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string
题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...
- E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)
http://codeforces.com/contest/862/problem/E 二分答案 一个数与数组中的哪个数最接近: 先对数组中的数排序,然后lower_bound #include &l ...
- 【构造】【分类讨论】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, ...
- 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 让x没有出现,以及0..x-1都出现就可以了. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/std ...
- 【Codeforces Round #435 (Div. 2) B】Mahmoud and Ehab and the bipartiteness
[链接]h在这里写链接 [题意] 让你在一棵树上,加入尽可能多的边. 使得这棵树依然是一张二分图. [题解] 让每个节点的度数,都变成二分图的对方集合中的点的个数就好. [错的次数] 0 [反思] 在 ...
随机推荐
- Centos7 zabbix 分布式监控
分布式监控 zabbix Server ===> zabbix agent (只能同一个局域网监控) 分布式监控: a. 分担压力,降低负载 b. 多机房 ...
- JSBridge实现示例
前言 参考来源 前人栽树,后台乘凉,本文参考了以下来源 Hybrid APP架构设计思路 marcuswestin/WebViewJavascriptBridge 楔子 本文介绍JSBridge的完整 ...
- MySQL课堂练习 20162315
练习内容 1.参考教材相关代码,提交能连接到world的截图(有学号水印) 2.查询world数据库,获得人口超过500万的所有城市的列表. 3.查询world数据库,获得New Jersey州所有城 ...
- BETA-2
前言 我们居然又冲刺了·二 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 过去两天完成了哪些任务 了解OpenCV下的视频参数及其调用方法 初步编码 接下来的计划 文档工作 速 ...
- 数据库SQL中Like的用法总结
最先做项目多次用到LIKE语句,下面总结下经常用到了. 语法 match_expression [ NOT ] LIKE pattern [ ESCAPE escape_character ] 参数 ...
- teamcity执行jmeter脚本使用Executable with parameters方式不能正确运行解决思路
如下图是选择command Line:Executable with parameters设置启动jmeter.bat 命令如下 command Executable: D:\apache-jmet ...
- selenium使用execl实现数据驱动测试
import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.uti ...
- ini_set
1.ini_set函数是设置选项中的值,在执行函数后生效,脚本结束的时候,这个设置也失效.ini_set 用于更改配置文件的配制,次更改仅用于此脚本的执行.不是所有的选项都能被改函数设置的. 2.in ...
- 【win10】浏览器Chrome 和edge 体验对比与使用心得
(1)Google和edge都内置了PDF阅读器,不用特意安装PDF软件了.桌面上的PDF文件可以直接用这两个浏览器打开. 然后对比来看,清晰度上美观度上,Chrome要比edge好一些.因为edge ...
- intel 的架构图
第一代: 第二代 第三代 以及对比