1. 程式人生 > >Codeforces 1137D(技巧)

Codeforces 1137D(技巧)

這樣的 flush 開始 cout ext next ++ 模擬 out

一開始寫的第一步讓0和1一起走然後第二步再讓0走會掛最後一個點……然後探索一下覺得主要問題在於我模擬的一步一步地走。如果這樣的話9 2這個數據會使第17步他倆就碰在final點了,而實際上我們想要的效果是他們走第18步時差一格,然後第20步碰上後大家一起,所以提前碰到會炸。故而要兩步兩步地走才行,發現01碰到了就跳出然後大家一起走。

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    auto Read = [](int &x) {
        cin >> x;
        for (int i = 0; i < x; i++) {
            string s; cin >> s;
        }
    };
    int cur = -1;
    while (cur != 2) {
        cout << "next 0\n" << flush;
        Read(cur);
        cout << "next 0 1\n" << flush;
        Read(cur);
    }
    while (cur != 1) {
        cout << "next";
        for (int i = 0 ;i <= 9; i++)
            cout << " " << i;
        cout << endl << flush;
        Read(cur);
    }
    cout << "done\n";
    return 0;
}

Codeforces 1137D(技巧)