首页 > 代码库 > LibreOJ #6. Guess Number

LibreOJ #6. Guess Number

二次联通门 : LibreOJ #6. Guess Number

 

 

 

/*
        LibreOJ #6. Guess Number
        
        交互题初体验
        用了二分判定
        

        感觉不错
*/
#include "interaction.h"

#define Max 1000010
inline int solve(int i) 
{
    register int l = 0, r = Max, Mid;
    int res;
    for (; l <= r; ) 
    {
        Mid = l + r >> 1;
        if (guess(i, Mid) >= 0)
        {
            res = Mid;
            r = Mid - 1;
        } 
        else 
            l = Mid + 1;
    }
    return res;
}

int Main ()
{
    int N = get_num();
    std :: vector<int> a(N);
    for (int i = 0; i < N; i++) 
        a[i] = solve(i);
    submit(a);
}
int ZlycerQan = Main ();
int main (int argc, char *argv[]) {;}

 

LibreOJ #6. Guess Number