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 ...
随机推荐
- 标准的Flask启动文件
最近有一些同学问了我一些项目结构的问题 所以今天给大家专门讲解 解耦后的项目 目录我会分为两种方式:一种是普通解耦 一种是多mvc解耦 首先 我没先建立我们程序的文件夹并且在这个文件夹内写一个和这个文 ...
- 定制二选一按钮SwitchButton
定制二选一按钮SwitchButton 效果: 源码: SwitchButton.h 与 SwitchButton.m // // SwitchButton.h // KongJian // // C ...
- [C++] 用Xcode来写C++程序[5] 函数的重载与模板
用Xcode来写C++程序[5] 函数的重载与模板 此节包括函数重载,隐式函数重载,函数模板,带参数函数模板 函数的重载 #include <iostream> using namespa ...
- jumpserver 问题,给自己看的哦,你们不准看哟
给自己看的,排版忽略! http://docs.jumpserver.org/zh/docs/setup_by_centos7.html 看完全部文档后解决不了再看下边的!!! docker 服务启动 ...
- zabbix日常监控项TCP连接状态(六)
TCP的连接状态对于我们web服务器来说是至关重要的,尤其是并发量ESTAB或者是syn_recv值,假如这个值比较大的话我们可以认为是不是受到了攻击,或是time_wait值比较高的话,我们要考虑看 ...
- 微信JSSDK与录音相关的坑
微信JSSDK与录音相关的坑 最近一直在做微信JSSDK与录音相关的功能开发, 遇到了各种奇尺大坑, 时不时冷不丁地被坑一道, 让我时常想嘶吼: "微信JSSDK就是个大腊鸡!!!!!!!! ...
- ubuntu 12.04 eclipse增加桌面快捷方式
1.创建桌面启动器(编辑/usr/share/applications/eclipse.desktop) [Desktop Entry] Encoding=UTF-8 Name=eclipse Com ...
- 判断浏览器是否为ie的最快方法
var ie = !-[1,]; alert(ie); 只要6 bytes!它利用了IE与标准浏览器在处理数组的toString方法的差异做成的.对于标准游览器,如果数组里面最后一个字符为逗号,JS引 ...
- ethers.js-5-Utilities
https://docs.ethers.io/ethers.js/html/api-utils.html 使用时再进行查看即可
- 非常简单的部署脚本(JavaWeb项目)和部署项目教程
这个部署方式,前提需要通过WinSCP工具将本地Maven项目打成zip包放到Linux对应的用户目录下,然后执行脚本便可以完成一键部署. 大家看到下面的脚本,可以发现一个显著的特点,部署脚本内容基本 ...