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 ...
随机推荐
- js判断状态
'<input type="radio" class="danxuan" name="danxuan" code="'||v ...
- 设计标签选择器TitleSwitch
设计标签选择器TitleSwitch 效果如下: 源码如下: TitleSwitch.h 与 TitleSwitch.m // // TitleSwitch.h // TitleSwitch // / ...
- Forefront TMG 之 ISP 冗余传输链路(ISP-R)
在 Forefront TMG 中,新增了ISP 冗余传输链路功能:在 TMG 中,你可以同时使用两条活动的外部链路,使用模式分为以下两种: 故障转移模式:在主要链路工作正常的情况下,所有的流量都通过 ...
- C++用法总结
1.C++的绝对值符号 如果是整形的,就是abs() 如果是浮点型的,是fabs() 这两个函数都从属于库函数math.h #include <cmath> or #include< ...
- springmvc常用的组件,注解,跳转
路径映射 XXXHandlerMapping 随开发配置越来越多 注解到java代码中来简化xml配置 请求到哪个Controller 控制器bean Controller 随着开发配置越来越多 注解 ...
- Shell定时删除日志
vim del_log.sh #!/bin/bash location="/home/dl/code/logs" find $location -mtime +4 -type f ...
- Hibernate入门步骤及概念
1.什么是Hibernate Hibernate是一个开发源代码的对象关系映射框架,它对JDBC进行非常轻量级的对象封装,使得程序员可以随心所欲地使用对象编程思维来操纵数据库.Hibernate可以应 ...
- 【收集】Python 微优化
1. 第二种方式可以节省寻找result的append属性的时间, 但会降低代码可读性和可维护性 # The way we're used to seeing it: result.append(&q ...
- 浅谈MyBatis缓存
在谈论MyBatis的缓存之前,我们先说说它的延迟加载,所谓延迟加载, resultMap中的association和collection标签具有延迟加载的功能.延迟加载的意思是说,在关联查询时,利用 ...
- myFocus 焦点图/轮播插件
最近产品突然就来个需求,要加轮播图,而且是立马要上线,于是乎发现了一个超级简便好用的轮播图插件myFocus,而且myFocus提供很多种风格,可以选择. 这里是使用说明 http://www.chh ...