跪求大佬帮我看看为啥cf返回tle呢,实在不明白qwq
查看原帖
跪求大佬帮我看看为啥cf返回tle呢,实在不明白qwq
265978
Retired楼主2022/2/11 13:06

题目

#include <iostream>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;

string ask(int x,int y){
    cout<<"? "<<x<<" "<<y<<endl;
    string s;cin>>s;
    return s;
}

int main()
{
    string ss;
    while(cin>>ss,ss!="end")
	{
        ll l=1,r=2;//先倍增再二分 
        string s;
        do{
        	s=ask(l,r);
        	if(s=="y")
        		l=r,r<<=1;
		}while(s=="y");
        //二分答案。 
        while(l<r){
            string s;
            int mid=l+r>>1;
            s=ask(l,mid);
            if(s=="x"){
                r=mid;
            }
            else if(s=="y"){
                l=mid+1;
            }
        }
        cout<<"! "<<l<<endl;
    }
    return 0;
}
2022/2/11 13:06
加载中...