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\n",mid); fflush(stdout); string s;cin >> s; if(s == ">=") L = mid; else r = mid-1; } printf("! %d\n",L); fflush(stdout); }