LibreOJ #6. Guess Number

Posted ZlycerQan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

loj #6.Guess Number

374 Guess Number Higher or Lower 猜数字大小

guess_procedure

1562 Guess the number

Guess the number

LeetCode Guess Number Higher or Lower