CodeForce 897 D. Ithea Plays With Chtholly

D. Ithea Plays With Chtholly
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem. Refer to the Interaction section below for better understanding.

Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.

Initially, Ithea puts n clear sheets of paper in a line. They are numbered from 1 to n from left to right.

This game will go on for m rounds. In each round, Ithea will give Chtholly an integer between 1 and c, and Chtholly needs to choose one of the sheets to write down this number (if there is already a number before, she will erase the original one and replace it with the new one).

Chtholly wins if, at any time, all the sheets are filled with a number and the n numbers are in non-decreasing order looking from left to right from sheet 1 to sheet n, and if after m rounds she still doesn't win, she loses the game.

Chtholly really wants to win the game as she wants to cook something for Willem. But she doesn't know how to win the game. So Chtholly finds you, and your task is to write a program to receive numbers that Ithea gives Chtholly and help her make the decision on which sheet of paper write this number.

Input

The first line contains 3 integers n, m and c ( means  rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process.

Interaction

In each round, your program needs to read one line containing a single integer pi (1 ≤ pi ≤ c), indicating the number given to Chtholly.

Your program should then output a line containing an integer between 1 and n, indicating the number of sheet to write down this number in.

After outputting each line, don't forget to flush the output. For example:

  • fflush(stdout) in C/C++;
  • System.out.flush() in Java;
  • sys.stdout.flush() in Python;
  • flush(output) in Pascal;
  • See the documentation for other languages.

If Chtholly wins at the end of a round, no more input will become available and your program should terminate normally. It can be shown that under the constraints, it's always possible for Chtholly to win the game.

Example
input
2 4 4
2
1
3
output
1
2
2
Note

In the example, Chtholly initially knew there were 2 sheets, 4 rounds and each number was between 1 and 4. She then received a 2 and decided to write it in the 1st sheet. Then she received a 1 and wrote it in the 2nd sheet. At last, she received a 3 and replaced 1 with 3 in the 2nd sheet. At this time all the sheets were filled with a number and they were non-decreasing, so she won the game.

Note that it is required that your program terminate immediately after Chtholly wins and do not read numbers from the input for the remaining rounds. If not, undefined behaviour may arise and it won't be sure whether your program will be accepted or rejected. Also because of this, please be careful when hacking others' codes. In the sample, Chtholly won the game after the 3rd round, so it is required that your program doesn't read the number of the remaining 4th round.

The input format for hacking:

  • The first line contains 3 integers n, m and c;
  • The following m lines each contains an integer between 1 and c, indicating the number given to Chtholly in each round.
题意:两个人玩游戏, Ithea最初将 n 张清晰的纸张排成一行。它们从左到右 1 n 编号。 这场比赛将进行m轮。在每一轮中,Ithea会给Chtholly从1到c之间的整数,而Chtholly需要选择其中一张来记下这个数字(如果之前已经有一个数字,她将会原来的数字覆盖)。在任何时候,Chtholly都可以赢,条件所是有的纸上都填了数字,而n个数字在从表1到表n的从左到右的顺序上是非递减顺序的,并且如果在m轮之后她仍然不赢,她输掉了比赛。

设输入的数为a

如果a<=c/2,从左向右找第一个未填的纸片或第一个大于a的纸片

如果a>c/2,从右向左找第一个未填的纸片或第一个小于a的纸片

每次输出后要判断是否获胜,获胜则退出输入。

#include<bits/stdc++.h>
#define maxn 1010
using namespace std;
int main()
{
    int n,m,c;
    int num[maxn];
    memset(num,0,sizeof(num));
    scanf("%d%d%d",&n,&m,&c);
    for(int j=0;j<m;j++)
    {
        int a;
        scanf("%d",&a);
        if(2*a<=c)
        {
            for(int i=1;i<=n;i++)
            {
                if(num[i]>a||num[i]==0)
                {
                    num[i]=a;
                    printf("%d\n",i);
                    fflush(stdout);
                    break;
                }
            }
        }
        else
        {
            for(int i=n;i>=1;i--)
            {
                if(num[i]<=a||num[i]==0)
                {
                    num[i]=a;
                    printf("%d\n",i);
                    fflush(stdout);
                    break;
                }
            }
        }
        bool flag=true;
        for(int i=2;i<=n;i++)
        {
            if(num[i]<num[i-1]||num[i]==0)
            {
                flag=false;
                break;
            }
        }
        if(num[1]==0)
            flag=false;
        if(flag)
            break;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值