《codeforces交互式题目》

https://codeforces.ml/gym/101021/problem/1

入门题。

对于交互式题目,就是通过自己询问的结果来判断下一次询问最后得出结果的过程。

对于打印出来的结果,都必须用fflush(stdout)来强制清空

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<string,int> pii;
const int N = 1e3+5;
const int M = 2e5+5;
const LL Mod = 1e9+7;
#define rg register
#define pi acos(-1)
#define INF 1e9
#define CT0 cin.tie(0),cout.tie(0)
#define IO ios::sync_with_stdio(false)
#define dbg(ax) cout << "now this num is " << ax << endl;
namespace FASTIO{
    inline LL read(){
        LL x = 0,f = 1;char c = getchar();
        while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
        while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
        return x*f;
    }
    void print(int x){
        if(x < 0){x = -x;putchar('-');}
        if(x > 9) print(x/10);
        putchar(x%10+'0');
    }
}
using namespace FASTIO;

int main()
{
    int L = 1,r = 1000000;
    while(L < r)
    {
        int mid = (L+r+1)>>1;
        printf("%d
",mid);
        fflush(stdout);
        string s;cin >> s;
        if(s == ">=") L = mid;
        else r = mid-1;
    }
    printf("! %d
",L);
    fflush(stdout);
}
View Code
原文地址:https://www.cnblogs.com/zwjzwj/p/13696198.html