WAx1求助
查看原帖
WAx1求助
639198
Steve_xh楼主2025/1/19 23:45

弘文了/kk

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
// const int MAXN=100005,mod=998244353,inf=0x3f3f3f3f;
int l=1,r=11,w=1;
const int s[]={0,1,10,100,1000,10000,100000,1000000,10000000ll,100000000ll,1000000000ll,10000000000ll};
char answer;
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    // for(int i=10;i>=1;i--){
    //     cout<<"? "<<s[i]<<endl;
    //     cin>>answer;
    //     if(answer=='Y'){
    //         cout<<"? "<<s[i]-1<<endl;
    //         cin>>answer;
    //         if(answer=='N'){
    //             cout<<"! "<<s[i];
    //             return 0;
    //         }
    //     }
    // }
    while(l<=r){
        int mid=(l+r)>>1;
        cout<<"? "<<s[mid]<<endl;
        cin>>answer;
        if(answer=='Y')
            w=mid,l=mid+1;
        else
            r=mid-1;
    }
    if(w==11){
        l=2,r=10;
        while(l<r){
            int mid=(l+r)>>1;
            cout<<"? "<<s[mid]-1<<endl;
            cin>>answer;
            if(answer=='Y')
                r=mid;
            else
                l=mid+1;
        }
        cout<<"! "<<s[r-1];
        return 0;
    }
    // cerr<<w;
    l=pow(10,w-1),r=l*10-1;
    while(l<r){
        int mid=(l+r)>>1;
        cout<<"? "<<mid<<"0"<<endl;
        cin>>answer;
        if(answer=='N')
            l=mid+1;
        else
            r=mid;
    }
    cout<<"! "<<r;
    return 0;
}

// 114514
// 100
2025/1/19 23:45
加载中...