Official

C - Yamanote Line Game Editorial by en_translator


In order to get accepted for this problem, write a program that simulates Takahashi’s move just as described in the Problem Statement.

During the game, store “is integer \(i\) already declared by any player?” for \(i = 1, 2, \ldots, 2N+1\) with a data structure like boolean array, and use it when deciding the next integer for Takahashi to declare.

Interactive tasks like this problem is often seen in programming contests. Typical problems are problems in which your program plays a game against the judge program, and problems in which your program guesses secret information that the judge program hinders through asking questions.

Here are some interactive tasks that have already appeared in AtCoder.

Here is a sample code in C++ language.

#include <iostream>
using namespace std;

bool used[2005];

int main(void)
{
  int n;
  
  cin >> n;
  while(1){
    for(int i = 1; i <= 2*n+1; i++){
      if(!used[i]){
        cout << i << endl;
	used[i] = true;
        break;
      }
    }
    
    int res;
    cin >> res;
    if(res == 0) break;
    used[res] = true;
  }
  
  return 0;
}

posted:
last update: