Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.82 KB | None | 0 0
  1. #include<iostream>
  2. #include<bits/stdc++.h>
  3. #include<algorithm>
  4. #include<limits>
  5. #define INFL 1000000000000000007
  6. #define INF 1000000007
  7. #define MOD 998244353
  8. #define N 50005
  9. #define K 505
  10. #define sh 400004
  11. #define M 8
  12. #define ll long long
  13. using namespace std;
  14. int reads;
  15. char scan;
  16. int f;
  17. string rev(string a)
  18. {
  19.     //just reverse the string
  20.     for(int i=0;i<a.length()/2;i++)
  21.         swap(a[i],a[a.length()-1-i]);
  22.     return a;
  23. }
  24. string comp(string a)
  25. {
  26.     //just complement the string
  27.     for(int i=0;i<a.length();i++){
  28.         if(a[i]=='0') a[i]='1';
  29.         else a[i]='0';
  30.     }
  31.     return a;
  32. }
  33. string dic(string a,string b)
  34. {
  35.     int d=0;
  36.     //look for index for mismatch between strings
  37.     while(d<a.length() && a[d]==b[d])
  38.         d++;
  39.     //if no mismatch found return any
  40.     if(d==a.length())
  41.         return a;
  42.     //else read and return the right one
  43.     reads--;
  44.     //increase d by 1 as it is 1 indexed
  45.     printf("%d\n",d+1);
  46.     cout.flush();
  47.     cin >> scan;
  48.     //only checking for unexpected behavior
  49.     if(scan=='\n') cin >> scan;
  50.     if(scan=='N') f=0;
  51.     //comparing scanned char to position in string
  52.     if(scan==a[d])
  53.         return a;
  54.     return b;
  55. }
  56. int main()
  57. {
  58.     int T,b;
  59.     cin >> T >> b;
  60.     int f=1;
  61.     for(int q=1;q<=T;q++){
  62.         string s;
  63.         cin >> s;
  64.         //only checking for N
  65.         if(s=="N") return 0;
  66.         // 15*10 reads
  67.         for(int i=0;i<15;i++){
  68.             //we need 10 reads every iteration
  69.             reads=10;
  70.             string poss[4];
  71.             // generate four possibilities for string
  72.             poss[0]=s;
  73.             poss[1]=comp(s);
  74.             poss[2]=rev(s);
  75.             poss[3]=rev(poss[1]);
  76.             //making decision about what is the string in 3 steps
  77.             poss[1]=dic(poss[0],poss[1]);
  78.             //f flag for ending if N scanned
  79.             if(f==0)
  80.                 return 0;
  81.             poss[2]=dic(poss[2],poss[1]);
  82.             if(f==0)
  83.                 return 0;
  84.             // reassign s at the last decision made
  85.             s=dic(poss[2],poss[3]);
  86.             if(f==0)
  87.                 return 0;
  88.             //just make the reaming reads
  89.             for(int j=0;j<reads;j++){
  90.                 printf("1\n");
  91.                 cout.flush();
  92.                 cin >> scan;
  93.                 //only checking for unexpected behavior
  94.                 if(scan=='\n')
  95.                     cin >> scan;
  96.                 if(scan=='N')
  97.                     return 0;
  98.             }
  99.         }
  100.         //output s after 150 query
  101.         cout << s << endl;
  102.         cout.flush();
  103.         // to scan Y here or N :(
  104.         cin >> scan;
  105.         //only checking for unexpected behavior
  106.         if(scan=='\n')
  107.             cin >> scan;
  108.         if(scan=='N')
  109.             break;
  110.     }
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement