1010B - Rocket - CodeForces Solution


binary search interactive *1800

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define nl '\n'
#define V vector

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int m, n;
    cin >> m >> n;
    V<bool> p(n);
    for(int i = 0; i < n; i++) {
        cout << m << endl;
        int judge;
        cin >> judge;
        if(judge == 0) {
            exit(0);
        }
        p[i] = judge == -1;
    }
    int pos = 0;
    int l = 1, r = m;
    while(l <= r) {
        int mid = (l + r) / 2;

        cout << mid << endl;
        int judge;
        cin >> judge;
        if(!p[pos]) judge = -judge;
        if(judge == 0){
            exit(0);
        } else if(judge == -1) {
            r = mid - 1;
        } else {
            l = mid + 1;
        }
        pos = (pos + 1) % n;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

810B - Summer sell-off
84A - Toy Army
185A - Plant
1749A - Cowardly Rooks
1749C - Number Game
1749B - Death's Blessing
1749D - Counting Arrays
1447B - Numbers Box
1594D - The Number of Imposters
984B - Minesweeper
837A - Text Volume
1566C - MAX-MEX Cut
1546A - AquaMoon and Two Arrays
897B - Chtholly's request
1363B - Subsequence Hate
437B - The Child and Set
1256B - Minimize the Permutation
733B - Parade
172A - Phone Code
148D - Bag of mice
421A - Pasha and Hamsters
1393A - Rainbow Dash Fluttershy and Chess Coloring
980E - The Number Games
219B - Special Offer Super Price 999 Bourles
560B - Gerald is into Art
322B - Ciel and Flowers
801B - Valued Keys
975C - Valhalla Siege
518B - Tanya and Postcard
514B - Han Solo and Lazer Gun