Ithea Plays With Chtholly (模拟)

Codeforces 896B Ithea Plays With Chtholly 交互/构造 题意有一个长度为n的数组和m次操作并给出一个正整数c。每次操作会给出一个数x,保证x为不大于c的正整数。要求你每次都把x放到数组的某个空位置或替代掉某个数。使得在m次操作结束之前满足数组的每个位置都有数且其单调不降。注意必须在线,也就是在输入下一个数之前就要输出当前数所放的位置且不能再更改。分析有点意思的脑洞题(其实并不难),在比赛快结束的时候才想到。不然估计就要掉回div2了。 就是设mid=c 阅读详情

Ithea Plays With Chtholly

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.

如果给的数小于等于c/2正着遍历板子,如果找到有大于这个数的替换否则到空位置放上,如果给的数大于c/2,倒着遍历板子

如果找到小于这个数的板子替换,否则找到第一个空板子放上。每次检查n个板子是否满了

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,c;
int sheet[1002];
int main(){
    scanf("%d%d%d",&n,&m,&c);
    while(m--){
        int x;
        scanf("%d",&x);
        int cnt = 0;
        if(x * 2 <= c){
            for(int i = 1; i <= n; i++){
                if(sheet[i] > x){
                    sheet[i] = x;
                    printf("%d\n",i);
                    break;
                }
                if(!sheet[i]){
                    sheet[i] = x;
                    cnt++;
                    printf("%d\n",i);
                    break;
                }
            }
        }
        else{
            for(int i = n; i >= 1; i--){
                if(sheet[i] < x){
                    sheet[i] = x;
                    printf("%d\n",i);
                    break;
                }
                if(!sheet[i]){
                    sheet[i] = x;
                    cnt++;
                    printf("%d\n",i);
                    break;
                }
            }
        }

        fflush(stdout);
        if(cnt == n) break;
    }
    return 0;
}

保姆级教学,教你在vscode和cursor上调试matlab!!! 保姆级教你如何在vscode或者cursor上面调试matlab 阅读详情

相关推荐

AI智能体协作:构建更精准的公司破产预测模型

公司破产预测对于金融机构、投资者和监管部门等具有至关重要的意义。准确的破产预测可以帮助金融机构提前做好风险防范,避免贷款损失;投资者可以根据预测结果调整投资组合,降低投资风险;监管部门可以及时发现潜在的金融风险,采取相应的监管措施。然而,传统的公司破产预测模型往往存在精度不高的问题,无法满足实际需求。本研究的目的是利用AI智能体协作的方式,构建一个更精准的公司破产预测模型。通过将多个AI智能体的优势进行整合,充分挖掘公司财务数据、市场数据等多源数据中的信息,提高预测的准确性和可靠性。

2501_92132293的博客 1081

致——世界上最幸福的女孩——Chtholly

世界上最幸福的女孩——Chtholly

白夕の旅途 8877

用大白话讲解Carplay(原创)

用大白话讲解Carplay: Carplay是美国苹果公司开发的一套服务,用户通过这套服务可以将iPhone与车载系统连接,然后在车载大屏上操作使用iPhone手机。个人理解,Carplay不能叫车载系统,不是操作系统,只能算一种服务。让你在车上的大屏上使用iPhone,这样用起来更方便,不需要在手机小屏幕上操作。基于这一点,有些人也说Carplay就是个投屏的功能,将手机屏幕投屏到了车机大屏上。可以简单这么理解,但是并不只是投屏这么简单,如果只是投屏的话,车子只是起到了一个显示器的功能,其实不止,手机和

cici2013的专栏 2万+

浅谈珂朵莉树(Chtholly Tree)——暴力而玄学的数据结构

关于它很珂学的名字… 珂朵莉树(Chtholly Tree),又称老司机树(Old Driver Tree),起源于CodeFoeces平台上编号为896C的一道题—— “ Willem, Chtholly and Seniorious ” (珂学家们此时不用翻译也知道这个名字是在说啥了) ,一位用户Old Driver在给出了线段树的正解之后,又发布了YY多年的 一份前所未有的玄学解法,其中利用......

CC_dsm的博客 2万+

树莓派4B:控制步进电机

文章目录准备阶段接线阶段树莓派程序 准备阶段 准备以下物品,淘宝都可以买到: 57步进电机 电源开关(220v转24v,3A,72W) 步进电机驱动器 电源线 电线 杜邦线 树莓派4B一套 具体型号如下: 接线阶段 整体:接线效果如下图 电源开关起220v转24v作用,很好接线,输出24v接入步进电机驱动器 步进电机驱动器的 A+ A- B+ B- 按提示接步进电机四线,步进电机上就会有说...

学习路上的鸭子的博客 1万+

管理信息系统(MIS)设计

一名读者可以借阅多本图书,而一本图书也可以被不同的读者借阅,所以读者与图书之间存在着多对多的借阅关系,读者与图书之间存在着多对多的联系,即m:n的联系。每一种图书属于一种图书类型,而一种图书类型可以包含很多本图书,因此可以得到图书类型与图书之间也存在着一种一对多的联系,即图书类型与图书是1:n的联系。系统应该实现以下功能:图书管理员可以维护图书信息,包括增加新书、修改图书信息、办理图书借阅登记、图书归还登记、过期图书处理、丢失图书处理及读者借阅证件信息的维护等;

m0_69718745的博客 2475

Interactive Problems(交互式问题) 2016.6.9

1、CodeForces_101021A Guess the Number #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned

追风蹑影 1616

基于wxWidgets框架,使用DialogBlocks建立OpenGL界面

前言 之前公司要求使用wxWidgets做GUI,基于OpenGL图形内核,开发三维可视化工具。目前初步开发工作基本已经完成,剩下都是完善了。这里记录一下最开始的框架搭建过程(当然是简化版啦)。wxWidgets结合OpenGL开发可以实现跨平台应用,再结合CMake和VS Code,整体开发工具用习惯了会感觉非常顺手。 界面编辑 首先,使用DialogBlocks新建一个工程,这里工程目录...

cyberobot的博客 2749

【CodeForces - 897D】Ithea Plays With Chtholly (交互题型,贪心,思维构造,题目信息)

题目大意: 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. ...

xuanweiace的博客 656

Kafka延迟队列实现方案全解析

$ \text{时间轮} = \text{环形数组} + \text{分层设计} $$需要补充代码实例或特定场景的优化方案可进一步细化,此大纲已覆盖核心技术路径。

lz989796的博客 816

南京邮电大学电工电子基础B实验六(组合逻辑电路)

南京邮电大学电工电子基础B实验五(组合逻辑电路);电工电子;南京邮电大学;计算机学院;实验报告;电路图;

亦是远方的小地方 1万+

Codeforces Round #703 (Div. 2) C interactive problem

这场div2被这个交互题打的头皮发麻。 20分钟我AC了AB两题,那是觉得这场要飞天,但开到C题的时候就懵逼了,题目是什么意思?输入是什么意思?输出又是什么鬼?%%%%% 因为这是本蒟蒻第一次写交互题,所以写这种题需要注意的点我完全不知道,于是乎出现了这个诡异的一幕:其他人拼命输出,而我却在学习what is interactive problem? 废话不多说,直接上题。 题目如下: 注释: 交互题,顾名思义就是一种通过不断给出信息,然后通过程序利用信息,最后得到答案的过程。 其不同于传统的题目,这种

weixin_50547586的博客 429

基于Keil软件实现OLED显示(江协科技HAL库)

没有HAL库的OLED驱动文件,可以看过来

2401_82728381的博客 1452

Ithea Plays With Chtholly

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,...

Sirius_han的博客 288

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Codeforces 897D. Ithea Plays With Chtholly (交互)

题目链接:D. Ithea Plays With Chtholly 题意:   给你n张纸,在纸上写字(在 1 - c之间)可以写m次数(,)。(主要是交互,让你判断) 题解:   首先,看到m>=n*c/2,我们假设从1位置放入数据,如果放入的数据大于前面已经放入的数据那就往后排小于就替换。这样放的话,每个位置替换最大的次数是C,所以最大的次数总数是n*c。发现正好差了...

225

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

CodeForce896 B. Ithea Plays With Chtholly

#include using namespace std; const int maxn = 1050 ; int n , m , c , temp ; int arr[maxn] ; int main(){ int num = 0 ; scanf("%d %d %d" , &n , &m , &c) ; memset(arr , -1 , sizeof(arr))

Samaritan_infi的博客 489

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

[Easy] CodeForces - 897D Ithea Plays With Chtholly | 贪心博弈

Codeforces 897D

PurityFan's 658

codeforces 897 D Ithea Plays With Chtholly(交互)

题意: 每次给你一个数,让你放到一个长度为n 的数组里,直到这个数组填满并且是不递减函数为止。需要 在m步内完成 c是给出的数的范围。 解题思路: 一种显然的暴力方法就是从1开始扫描,遇到第一个大于x的或是a[i]==0的就放。 但是还有显然的卡掉这种暴力的做法,就是把数n-1逐个给出,就每次要替换,这样的话就需要n^2次,显然不行。 所以应该能想到从两边,开始扫描,让大于c...

johsnows的博客 676

codeforces897 D Ithea Plays With Chtholly【贪心 + 交互题】

交互输入题 给你 n m c 代表有n张白纸,编号1-n, 系统会给你m次以内 得询问 每次给你一个[1 , c]的数字 你可以将这个数字填在某张纸上 如果该纸上有写数字了 你可以对其进行更改 要你打印出 每一次系统给的数字你是填在的纸的编号 请问如何填能够在 所有纸被填满的那一刻 让纸上的数字沿着编号非递减 题解: 有 m的取值范围 为 c/2 * n 所以每张纸最多都可以...

OOOak 531

Codeforces D - Ithea Plays With Chtholly

D - Ithea Plays With Chtholly 思路:考虑每个位置最多被替换c/2次 那么折半考虑,如果小于c/2,从左往右替换,大于c/2总右往左替换,只有小于这个数(从左往右)或者大于这个数(从右往左)才会被替换,所以每个位置最多被替换c/2次。 代码: #include<bits/stdc++.h> using namespace std; #def...

weixin_33712987的博客 156

codeforces 897D - Ithea Plays With Chtholly

D. Ithea Plays With Chtholly time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output This is an interactive problem. Refer to the Interaction secti

樱花满地集于我心,楪舞纷飞祈愿相随 1291

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.

DlPF_C的博客 477

【CodeForces】896 B. Ithea Plays With Chtholly

【题目】B. Ithea Plays With Chtholly 【题意】交互题,有n格,每次给一个[1,c]的数字,回答填入的位置后再次给数字,要求在m轮内使n格填满且数列不递减。n,m>=2,1<=c<=1000,1<=n*[c/2]<=m<=1000。 【算法】贪心 【题解】对于每次的数字x,找到第一个严格大于的位置替换之(或占一个新的空位置)。 ...

weixin_33895604的博客 101

题解 | 【CF896B】 Ithea Plays With Chtholly

题目链接:Here 给 \(m\) 个数,放到 \(1→n\) 一个位置上,若 \(1→n\) 都被填满且不下降就胜。强制在线。 看到题忽然觉得是水题,这不就最长不下降子序列的那个吗!直接上个二分就准备交了。 事实证明头铁了(怎么可能这么简单,2000分啊!) 反例: 15 5 9 29 1 8 1 7 若一个从前往后一个从后往前就可以完成,而那个做法还只填了 1 1 7 呢! 问题出在哪...

橘嘉禾 105

codeforces 896 B. Ithea Plays With Chtholly(构造||贪心)

http://codeforces.com/contest/896/problem/B 题意:交互题,有n格,每次给一个[1,c]的数字,回答填入的位置后再次给数字,要求在m轮内使n格填满且数列不递减。n,m>=2,1<=c<=1000,1<=n*[c/2]<=m<=1000。 思路:看到题目,我首先思考给出m>=nc/2 有什么用,一定能构造出序列,那么...

- 回忆゛ 267
上一篇: Goldbach`s Conjecture LightOJ - 1259(筛素数)
下一篇: Dream City ZOJ - 3211 (贪心+dp)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值