III USP Freshmen ContestH. MaratonIME gets candies

这题挺有意思的,刚开始不会这交互题,模仿着做了一题就会了,蛮简单 的

这题我用2分,结果wa了,想了一下发现,1到1e9二分50次完全不够用啊,那就转换一下思维,先求出在10^n~10^(n+1)的n

然后进行二分,这样居然a了。。。

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const double g=10.0,eps=1e-9;
const int N=300000+10,maxn=16,inf=9999999;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll l=1,r=1;
    string str;
    for(int i=1;i<=10;i++)
    {
        cout<<"Q "<<l<<endl;
        cout.flush();
        cin>>str;
        if(str=="=")return 0;
        if(str==">")l*=10;
        else if(str=="<")
        {
            r=l;
            l/=10;
            break;
        }
    }
    for(int i=1;i<=50;i++)
    {
        ll m=(l+r)/2;
        cout<<"Q "<<m<<endl;
        cout.flush();
        cin>>str;
        if(str==">")l=m;
        else if(str=="<")r=m;
        else return 0;
    }
    return 0;
}
View Code

 

posted @ 2017-05-26 18:03  walfy  阅读(345)  评论(0编辑  收藏  举报