102442: [AtCoder]ABC244 C - Yamanote Line Game

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

Takahashi and Aoki will play the following game against each other.

Starting from Takahashi, the two alternatingly declare an integer between $1$ and $2N+1$ (inclusive) until the game ends. Any integer declared by either player cannot be declared by either player again. The player who is no longer able to declare an integer loses; the player who didn't lose wins.

In this game, Takahashi will always win. Your task is to actually play the game on behalf of Takahashi and win the game.

Constraints

  • $1 \leq N \leq 1000$
  • $N$ is an integer.

Input and Output

This task is an interactive task (in which your program and the judge program interact with each other via inputs and outputs).
Your program plays the game on behalf of Takahashi, and the judge program plays the game on behalf of Aoki.

First, your program is given a positive integer $N$ from Standard Input. Then, the following procedures are repeated until the game ends.

  1. Your program outputs an integer between $1$ and $2N+1$ (inclusive) to Standard Output, which defines the integer that Takahashi declares. (You cannot output an integer that is already declared by either player.)
  2. The integer that Aoki declares is given by the judge program to your program from Standard Input. (No integer that is already declared by either player will be given.) If Aoki has no more integer to declare, $0$ is given instead, which means that the game ended and Takahashi won.

Notes

  • After each output, you must flush Standard Output. Otherwise, you may get TLE

Input

题意翻译

**本题为 IO 交互题。** 高桥和青木两人玩一种对战游戏。桌上有 $(2n+1)$ 张牌,上面分别写着 $1$ 到 $2n+1$ 这 $(2n+1)$ 个数各一遍。两个人从高桥开始轮流抽牌。轮到某个人时,若这个人没牌可抽,则这个人输掉了游戏,另一方则胜利了。可以证明,在这个游戏中,高桥一定会胜出。 你的任务是编写一个程序模拟高桥,与判决程序模拟的青木进行对决。首先输入一个正整数 $n$ ,然后重复以下步骤: 1. 你的程序会输出一个正整数,作为高桥抽的牌上写的数字(不能输出任何已抽过的牌上的数字); 1. 判决程序会从你的程序的标准输入输入一个正整数,作为青木抽的牌上写的数字(不会输入任何已抽过的牌上的数字)。如果没有可以抽的牌,程序会输入 $0$ ,这时高桥获胜,游戏结束。 **请注意:** 1. 每次输出后,请用`flush`刷新标准输出,否则可能会 TLE 。 1. 在高桥获胜,游戏完成后请立即结束程序,否则可能不会 AC 。 1. 若游戏过程中你的程序出现了不正确的输出则错误,但当时的判决结果可能不确定,所以不一定会 WA 。

Output

得分:300分

问题描述

Takahashi 和 Aoki 将要玩一个游戏。

从 Takahashi 开始,两人交替宣布一个 1 到 2N+1(含)之间的整数,直到游戏结束。无论哪个玩家宣布的整数都不能再次被宣布。无法再宣布整数的玩家输掉游戏;没有输掉的玩家赢得游戏。

在这个游戏中,Takahashi 总是会赢。你的任务是代表 Takahashi 并赢得游戏。

限制条件

  • $1 \leq N \leq 1000$
  • $N$ 是一个整数。

输入和输出

这是一个交互式任务(你的程序和裁判程序通过输入和输出进行交互)。
你的程序代表 Takahashi 参与游戏,裁判程序代表 Aoki 参与游戏。

首先,你的程序从标准输入接收到一个正整数 $N$。然后,以下程序将一直重复直到游戏结束。

  1. 你的程序向标准输出输出一个 1 到 2N+1(含)之间的整数,定义 Takahashi 宣布的整数。你不能输出已经被两个玩家之一宣布的整数。
  2. Aoki 宣布的整数由裁判程序向你的程序从标准输入给出。如果 Aoki 没有更多可以宣布的整数,将给出 0,意味着游戏结束且 Takahashi 赢得游戏。

注意

  • 每次输出后,你必须刷新标准输出。否则,你可能会得到 TLE

加入题单

算法标签: