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

交互题

fflush(stdout)

调试:

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

  1 #include <cstdio>
  2 #include <cstdlib>
  3 #include <cmath>
  4 #include <cstring>
  5 #include <time.h>
  6 #include <string>
  7 #include <set>
  8 #include <map>
  9 #include <list>
 10 #include <stack>
 11 #include <queue>
 12 #include <vector>
 13 #include <bitset>
 14 #include <ext/rope>
 15 #include <algorithm>
 16 #include <iostream>
 17 using namespace std;
 18 #define ll long long
 19 #define minv 1e-6
 20 #define inf 1e9
 21 #define pi 3.1415926536
 22 #define E  2.7182818284
 23 const ll mod=1e9+7;//998244353
 24 const int maxn=1e3+10;
 25
 26 char str[maxn];
 27 int pos[2],s,t,len=inf,x,y;
 28 char result[maxn]="01\0";
 29 int nn=2;
 30
 31 int cal()
 32 {
 33     int i,v=0;
 34     for (i=1;i<=nn;i++)
 35         if (str[i]!=result[i-1])
 36             v++;
 37     return v;
 38 }
 39
 40 //'l'-'r' must have num
 41 void work(int l,int r,int num)
 42 {
 43     if (l==r)
 44     {
 45         pos[num]=l;
 46         return;
 47     }
 48
 49     int i,m=(l+r)>>1;
 50     for (i=l;i<=m;i++)
 51         str[i]=((str[i]-48) ^ 1)+48;
 52     printf("? %s\n",str+1);
 53     fflush(stdout);
 54     scanf("%d",&x);
 55 //        x=cal();
 56
 57     for (i=l;i<=m;i++)
 58         str[i]=((str[i]-48) ^ 1)+48;
 59
 60     if (y-x==m-l+1)
 61     {
 62         pos[num]=l;
 63         return;
 64     }
 65     else
 66     {
 67         if (m-l+1<len)
 68         {
 69             len=m-l+1;
 70             s=l;
 71             t=m;
 72         }
 73     }
 74
 75     if (x-y!=m-l+1)
 76         work(l,m,num);
 77     else
 78         work(m+1,r,num);
 79 }
 80
 81 int main()
 82 {
 83     int n,i;
 84     scanf("%d",&n);
 85
 86     for (i=1;i<=n;i++)
 87         str[i]='1';
 88     str[n+1]='\0';
 89     printf("? %s\n",str+1);
 90     fflush(stdout);
 91     scanf("%d",&y);
 92 //        y=cal();
 93     work(1,n,0);
 94
 95     if (len>0)
 96     {
 97         for (i=1;i<=n;i++)
 98             str[i]='0';
 99         str[n+1]='\0';
100         printf("? %s\n",str+1);
101         fflush(stdout);
102         scanf("%d",&y);
103 //            y=cal();
104         if (len==inf)
105             s=1,t=n;
106         work(s,t,1);
107     }
108
109     printf("! %d %d",pos[0],pos[1]);
110     return 0;
111 }

转载于:https://www.cnblogs.com/cmyg/p/9521040.html

D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)相关推荐

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

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

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

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

  3. A Perfectly Balanced String? (Codeforces Round #785 (Div. 2))

    题目大意:找出是否存在子串中俩相同字母之间是否存在相同字母(比如abbca,存在bbc不是平衡三元组,故输出NO)思路:双指针以减小时间复杂度 #include <iostream> #i ...

  4. Codeforces Round #628 (Div. 2) F. Ehab‘s Last Theorem dfs树

    传送门 文章目录 题意: 思路: 题意: 给你个nnn个点mmm条边的图,可以选择完成以下两个任务中的一个: (1)(1)(1)找出大小恰好为n\sqrt nn​的一个独立集. (2)(2)(2)找出 ...

  5. Codeforces Round #628 (Div. 2) E. Ehab‘s REAL Number Theory Problem 巧妙的质因子建图

    传送门 文章目录 题意: 思路: 题意: 给你nnn个数,每个数的因子个数不超过777个,选出最少的数使其乘积为平方数. n≤1e5n\le 1e5n≤1e5 思路: 由于因子不超过777个,所以由约 ...

  6. Codeforces Round #624 (Div. 3) E. Construct the Binary Tree 思维 + 构造

    传送门 文章目录 题意: 思路: 题意: 给你n,dn,dn,d,让你构造有nnn个点的二叉树,他们每个节点深度和为ddd. n,d≤3000n,d\le 3000n,d≤3000. 思路: 先考虑不 ...

  7. Codeforces Round #617 (Div. 3) E2. String Coloring (hard version) 思维 + dp + Dilworth定理

    传送门 文章目录 题意: 思路: 题意: 让你给一个串染色,不同颜色且相邻的一对字符可以互换位置,用最少的颜色,使交换后这个字符串字典序最小. 思路: 考虑将字符串分成若干个非递减的子序列,由于其非递 ...

  8. Codeforces Round #656 (Div. 3) D. a-Good String

    Codeforces Round #656 (Div. 3) D. a-Good String 题目链接 You are given a string s[1-n] consisting of low ...

  9. Codeforces Round #644 (Div. 3) H.Binary Median

    题目链接 Consider all binary strings of length m (1≤m≤60). A binary string is a string that consists of ...

最新文章

  1. Ubuntu下Nginx/PHP/MYSQL开发环境的配置方法
  2. 计算机制图 教学大纲,《计算机制图》课程教学大纲.doc
  3. C# AppDomain
  4. 2月上旬国内域名总量止跌回升 净增长量达8574个
  5. android运行时状态,Android 如何保存Android 运行时状态
  6. python turtle绘制柱状图_python绘制图形(Turtle模块)
  7. loardrunner- 集合点函数设置
  8. L1-057 PTA使我精神焕发 (5 分)-PAT 团体程序设计天梯赛 GPLT
  9. 计算机Word2010在线做题,Word2010题库(答案)试题.doc
  10. 工程计算——实战:追赶法扰动分析
  11. 安装mp4,mp3等媒体解码器
  12. 服务器系统启用flash,基础设置:Windows Server 2012及2012R2 启用IE Flash
  13. android投屏功能开发,Android PC投屏功能实现的示例代码
  14. 没有apihost什么意思_热文:2021年没有立春什么意思
  15. java 将html转为word导出 (富文本内容导出word)
  16. 计算机勾兑双绝是谁发明,舌尖上的五粮液——记勾兑大师范玉平(图)
  17. simple-uploader.js 文档
  18. C语言数组实现丢手绢问题(约瑟夫问题)
  19. 操作系统中pv操作用c语言,操作系统-pv操作.doc
  20. ch552开发环境配置

热门文章

  1. 玻璃体混浊研究中需要解决的问题(持续更新中)
  2. hive的静态分区与动态分区-用法实例
  3. 《随机过程》第二版-Ross印刷排版勘误问题列表(转载+自己新增+持续更新中)
  4. Severstal: Steel Defect Detection比赛的discussion调研
  5. kaggle notebook中免密码进行push
  6. c++调用cplex求解例子_Java调用cplex求解运输问题
  7. linux 简单Shell程序设计,利用linux下的c语言编程来简单的实现一个shell功能实现!...
  8. Linux shell利用sed如何批量更改文件名详解
  9. win下 cmd 查询本机开了哪些端口 并查看开启端口的软件
  10. Teams新功能更新【六月底】Microsoft Teams: Music on Hold