cf1104d二分+数学

#include<bits/stdc++.h>
using namespace std;

bool ask(int x,int y){
    printf("? %d %d\n",x,y);
    fflush(stdout);
    char buf[4];
    scanf("%s",buf);
    return buf[0]=='x';
}

int work(){
    if(ask(0,1))return 1;
    int l=1,r,ans,mid;
    while(ask(l*2,l))l*=2;
    r=l*2+1,r=min(r,1000000000);
    while(l<=r){
        mid=l+r>>1;
        if(ask(mid,(mid+1)/2))//mid小于猜的数 
            l=mid+1;
        else ans=mid,r=mid-1;
    }
    return ans;
    
}

int main(){
    char cmd[32];
    while(1){
        scanf("%s",cmd);
        if(strcmp(cmd,"start")==0){
            printf("! %d\n",work());
            fflush(stdout);
        }
        else break;
    }
} 

 

posted on 2019-01-23 12:43  zsben  阅读(185)  评论(0编辑  收藏  举报

导航