高桥和赤井间非常有趣的交互游戏,玩法有点类似于数字炸弹(谁喊道相同的输)
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.
我们的程序扮演高桥,评测姬cos赤井
First, your program is given a positive integer N from Standard Input. Then, the following procedures are repeated until the game ends.
首先我们得程序要接受一个评测姬给的数字,(该数字决定双方喊出的数字的范围),以下的步骤直到游戏结束前会反复进行
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.)
我们的程序输出一个在闭区间[1,2n+1]的数,这个数不能是已经被喊过的
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.
赤井没有数可以喊了就给一个0,此时程序进程结束,就AC了
#include <bits/stdc++.h>
using namespace std;
bool a[2005];//这里用来标记已经被声明过的数
int N, x = 114514;//哼哼哼,啊啊啊啊啊啊啊啊啊啊啊啊
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N;
cout << "1" << endl;//我方先手,喊个1(只要是范围内的数就可以,这里是方便代码编写)
memset(a, 0, sizeof(a));
while (1) {
cin >> x;
if (!x)//判断是否可以结束
return 0;
a[x] = 1;//放到while外面会WA,不写会TLE
for (int i = 2; i <= 2 * N + 1; i++)//从小到大扫描
if (a[i])
continue;//如果这个数被声明了,就跳过
else {
cout << i << endl;//没被声明,就输出并标记一下
a[i] = 1;
break;
}
}
return 0;
}