D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
生活随笔
收集整理的這篇文章主要介紹了
D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
http://codeforces.com/contest/862/problem/D
?
交互題
fflush(stdout)
?
調(diào)試:
先行給出結(jié)果,函數(shù)代替輸入
?
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 }?
轉(zhuǎn)載于:https://www.cnblogs.com/cmyg/p/9521040.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的D. Mahmoud and Ehab and the binary string Codeforces Round #435 (Div. 2)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 汽车电子传感器科普:激光雷达 毫米波雷达
- 下一篇: Star sky CodeForces