zoukankan      html  css  js  c++  java
  • Codeforces Round #449 B. Ithea Plays With Chtholly

    http://codeforces.com/contest/896/problem/B

    题意:

    交互题

    n张卡片填m个1到c之间的数,1<=n*ceil(c/2)<=m

    最后填出一个单调非降序列,输出每次填的位置

    <=c/2:

    从左开始扫描,遇到空位 或 比原数更优(<原数)就放

    >c/2:

    从右开始扫描,遇到空位 或 比原数更优(>原数)就放

    以<=c/2为例:

    空位就放,<原数就覆盖,>=原数就往后扫

    这样每个位置最多只会被覆盖c/2次,(c/2 ~1 各覆盖一次)

    又因为 m>=n*ceil(c/2)

    所以最后一定有解

    #include<cstdio>
    
    using namespace std;
    
    int a[1001];
    
    int main()
    {
        int n,m,c,x;
        scanf("%d%d%d",&n,&m,&c);
        int mid=c>>1;
        int sum=0;
        while(m--)
        {
            scanf("%d",&x);
            if(x<=mid)
            {
                for(int i=1;;++i)
                {
                    if(!a[i])
                    {
                        a[i]=x;
                        sum++;
                        printf("%d
    ",i);
                        break;
                    } 
                    else if(a[i]>x)
                    {
                        a[i]=x;
                        printf("%d
    ",i);
                        break;
                    }
                }
            }
            else
            {
                for(int i=n;;--i)
                {
                    if(!a[i])
                    {
                        a[i]=x;
                        sum++;
                        printf("%d
    ",i);
                        break;
                    }
                    else if(x>a[i])
                    {
                        a[i]=x;
                        printf("%d
    ",i);
                        break;
                    }
                }
            }
            fflush(stdout);
            if(sum==n) return 0;
        }
    }
    B. 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.
  • 相关阅读:
    不用递归实现List转Tree
    spring cloud stream 局部异常和全局异常混乱
    HTTP协议详解(真的很经典)
    Python3 多线程压测接口数据:写入到influxdb:通过grafana展示
    Eclipse使用git最简易流程
    oracle patch包一定要775的权限
    安装19c grid时CRS-1705错误
    Ubutun 设置开机启动程序
    利用selenium将edge浏览器里面的网页保存为pdf
    Ruckus ICX7150 Switch License Upgrade from 1G to 10G
  • 原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/8046084.html
Copyright © 2011-2022 走看看