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.
- practice contest B - Interactive Sorting ( https://atcoder.jp/contests/practice/tasks/practice_2 )
- AtCoder Petrozavodsk Contest 001 C - Vacant Seat ( https://atcoder.jp/contests/apc001/tasks/apc001_c )
- AtCoder Regular Contest 078 E - Awkward Response ( https://atcoder.jp/contests/arc078/tasks/arc078_c )
- AtCoder Regular Contest 070 F - HonestOrUnkind ( https://atcoder.jp/contests/arc070/tasks/arc070_d )
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: