关于此题2024-2025 ICPC, NERC, Southern and Volga Russian Regional Contest_G. Guess One Character

//记录一下思路历程:首先是毫无头绪
//然后想了很久注意到我可以询问01的个数和10的个数,那么这个字符串只能是010101...或者101010...这样的字符串,通过填充1到1旁边或者填充0到0旁边得到,如果01和10的数量不相同,那么01多肯定是0开头,10多肯定是1开头
//然后想到可以看1和0的个数奇偶性来判断,但是这样明显是错的
//接着想到由于在01和10相同的情况下,只有101010...和010101...的情况,设01和10数量为a,那么只需再询问11的数量为b,此时前者1的数量可以表示为b+a+1,后者则为b+a,但是这样区分需要4个询问
//再想到由于想要区分开来一定要知道1的数量和11的数量,所以先把这两个问了,再想到剩下的一次机会我需要知道这个字符串到底是101010...还是010101...,我才能用11的数量算1的数量,那就直接问01或者10的数量,假定问01,那么若是第一种情况,01数量加上11的数量应为1的数量+1,若是第二种情况则应为1的数量,这样这道题就解决了
#include<bits/stdc++.h>
    
using namespace std;
    
int t;
int n;

int ask(string s) {
    int tmp;
    cout << 1 << ' ' << s << '\n';
    cout.flush();
    cin >> tmp;
    return tmp;
}

void out(int pos,int ans) {
    cout << 0 << ' ' << pos << ' ' << ans << '\n';
    cout.flush();
    int x;
    cin >> x;
    if(x == -1) exit(0);
}
    
void solve() {
    cin >> n;
    int a = ask("1");
    int b = ask("11");
    int num = ask("01");
    if(a == b + num) out(1,0);
    else out(1,1);
}
    
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> t;
    while(t--) solve();
    
    return 0;
}
posted @ 2025-03-19 21:45  孤枕  阅读(28)  评论(0)    收藏  举报