【題目敘述】Problem 4. ESAb ATAd
#include <bits/stdc++.h>
using namespace std;
int t, b, a[105], s, d, l, r, cnt, tmp;
char c;
int main(){
cin >> t >> b;
while (t--){
memset(a, -1, sizeof(a));
s = -1;
d = -1;
l = 1;
r = b;
cnt = 0;
while (l <= r){
if (cnt%10 == 0){
if (s != -1){
cout << s << endl;
cnt++;
cin >> tmp;
if (tmp != a[s]){
for (int j = 1; j <= l; j++){
a[j] ^= 1;
}
for (int j = r; j <= b; j++){
a[j] ^= 1;
}
}
}
if (d != -1){
cout << d << endl;
cnt++;
cin >> tmp;
if (tmp != a[d]){
for (int j = 1; j <= l; j++){
swap(a[j], a[b+1-j]);
}
}
}
}
if (cnt%10 == 9){
cout << 1 << endl;
cnt++;
cin >> tmp;
continue;
}
cout << l << endl;
cnt++;
cin >> a[l];
cout << r << endl;
cnt++;
cin >> a[r];
if (a[l] == a[r] && s == -1) s = l;
if (a[l] != a[r] && d == -1) d = l;
l++;
r--;
}
for (int i = 1; i <= b; i++){
cout << a[i];
}
cout << endl;
cin >> c;
if (c == 'N') return 0;
}
}