日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。