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

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 3in 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.

题目大意:

给一个有n个格子从左到右排列的白板,系统每次随机给你一个1-c的数字, 请你设计一个算法,每轮把系统给你的这个数字填到白板上,如果白板的这一格已经填有数字,就将其擦去填新的数。要求这个算法在给定的m轮内填满n个格子,并保证这n个格子从左至右是一个不减序列 。每次输出填到哪里。

解题报告:

   注意到m的范围,给了很明显的提示了,这个m还是很大的,相当于n个格子每个都可以写c/2次,那就把可能出现的数字1-c二分,如果小于等于c/2就从左边开始填,否则从右边开始填,那么一定可以构造出来。填的时候左侧维护一个递增序列,右侧维护一个递减序列,如果遇到空的格子直接填上去,做不到维护不增就替换第一个大于(右边填起就是小于)这个数的数字。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 2e5 + 5;
int now;
int n,m,c,a[MAX];
int main()
{cin>>n>>m>>c;c/=2;while(m--) {int x;scanf("%d",&x);if(x <= c) {for(int i = 1; i<=n; i++) {if(a[i] == 0 || a[i] > x) {a[i] = x;printf("%d\n",i);//cout << i << endl;fflush(stdout);break;}}}else {for(int i = n; i>=1; i--) {if(a[i] == 0 || a[i] < x) {a[i] = x;printf("%d\n",i);//cout << i << endl;fflush(stdout);break;}}}now = 0;for(int i = 1; i<=n; i++) {if(a[i] != 0) now++;}if(now == n) break;}return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440727.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

红帽子linux生效环境变量,RedHat Linux 5无法使用ifconfig的解决方法

ifconfig是Linux显示网络设备的命令&#xff0c;能够设置网络设备的状态&#xff0c;但在RedHat Linux 5系统中&#xff0c;有时会遇到ifconfig命令无法使用的情况&#xff0c;下面小编就给大家介绍下RedHat Linux 5无法使用ifconfig命令的解决方法。一起去看看吧&#xff01;在…

关于交互题---Idleness limit exceeded(codeforces)

Idleness limit exceeded的中文&#xff1a;懒惰超过限制。----来自有道翻译 大概意思是在该输出的情况下没有输出数据 比如这个&#xff1a; 而且一般都会提醒你&#xff1a;&#xff08;在每条输出之后加&#xff09; After outputting each line, dont forget to flush t…

Linux如何搭建服务器eb,Linux下CRMEB环境搭建

环境准备:PHP7.0.33MySQL5.7Apache2.4PHP环境安装:sudo apt-get install php-pear php7.0-cli php7.0-common php7.0-curl \php7.0-dev php7.0-fpm php7.0-json php7.0-mbstring php7.0-mcrypt \php7.0-mysql php7.0-opcache php7.0-zip php7.0-intl php7.0-gd php7.0-xmlMySQL…

【EOJ Monthly 2019.02 - A】回收卫星(交互题型,二分)

题干&#xff1a; 单测试点时限: 1.0 秒 内存限制: 256 MB “这个世上没有无用的齿轮&#xff0c;也只有齿轮本身能决定自己的用途。” 就像太空中的卫星&#xff0c;虽然不计其数&#xff0c;但都各司其职。 但没有一个东西是能够永远无损的。为了便于回收及修理&#xf…

windows 调用linux .a lib,动态链接库及静态链接库(windows下的.dll .lib和linux下的.so .a)...

动态链接库及静态链接库(windows下的.dll .lib和linux下的.so .a) 库有动态与静态两种&#xff0c;动态通常用.so为后缀&#xff0c;静态用.a为后缀。例如&#xff1a;libhello.so libhello.a 为了在同一系统中使用不同版本的库&#xff0c;可以在库文件名后加上版本号为后缀,例…

【EOJ Monthly 2019.02 - B】解题(思维,抽屉原理,暴力,模运算,优化,tricks)

题干&#xff1a; 单测试点时限: 2.0 秒 内存限制: 1024 MB “我把房门上锁&#xff0c;并非为了不让她进去&#xff0c;而是为了防止自己逃到她身边”。 她又被数学难住了。QQ 小方当然是不会对女生说”不”的。 她的数学题是这样的&#xff0c;她得到了一个十进制大整数…

linux socket ip层配置,Linux下Socket通信(TCP实现)

近期在做的项目中&#xff0c;涉及到了进程间数据传输&#xff0c;系统的原本实现是通过管道&#xff0c;但是原有的实现中两个进程是在同一台机器&#xff0c;而且两个进程的关系为父子关系&#xff0c;而我们要做的是将其中一个进程移植到服务器上&#xff0c;因此两个进程要…

【EOJ Monthly 2019.02 - D】进制转换(思维,取模,高精度大数)

题干&#xff1a; 单测试点时限: 2.0 秒 内存限制: 256 MB “他觉得一个人奋斗更轻松自在。跟没有干劲的人在一起厮混&#xff0c;只会徒增压力。” QQ 小方决定一个人研究研究进制转换。 很快&#xff0c;QQ 小方就遇到问题了。他现在想知道在十进制范围 [l,r] 内有多少整…

linux i2c触摸屏驱动程序,触摸屏i2c设备和驱动的创建流程及方法

添加i2c设备的流程&#xff1a;1. 初始化 i2c_board_info 结构信息 和 i2c_driver 结构//设备驱动结构体static struct i2c_driver goodix_ts_driver {.probe goodix_ts_probe,.remove goodix_ts_remove,#ifndef CONFIG_HAS_EARLYSUSPEND.suspend goodix_ts_su…

【EOJ Monthly 2019.02 - E】中位数(二分 ,中位数 ,−1/1变换,dp求解DAG最长路)

题干&#xff1a; E. 中位数 单测试点时限: 10.0 秒 内存限制: 256 MB “你的地图是一张白纸&#xff0c;所以即使想决定目的地&#xff0c;也不知道路在哪里。” QQ 小方最近在自学图论。他突然想出了一个有趣的问题&#xff1a; 一张由 n 个点&#xff0c;m 条边构成的…

linux桌面变成黑白,用虚拟机装了linux后开启为什么界面是黑色的呢?

20寸显示器的标准分辨率是1680*1050进入到/boot/grub/目录下&#xff0c;然后就可以看到里面有个名为menu.lst的文件&#xff0c;用vim将其打开&#xff0c;可以看到以下内容&#xff1a;# grub.conf generated by anaconda## Note that you do not have to rerun grub after m…

【EOJ Monthly 2019.01 - E】唐纳德先生与假骰子(假概率问题)

题干&#xff1a; 单测试点时限: 6.0 秒 内存限制: 1024 MB 嗨&#xff0c;唐纳德先生又来了。 他又带了一枚假骰子&#xff0c;这个骰子的各个面的点数依然是 1,2,3,4,5,6 &#xff0c;但是六个面向上的概率却不一定都是 1/6 &#xff0c;而变成了 p1,p2,p3,p4,p5,p6 。 …

linux 编译安装picocom,Linux pico命令

Linux pico命令Linux pico命令用于编辑文字文件。pico是个简单易用、以显示导向为主的文字编辑程序&#xff0c;它伴随着处理电子邮件和新闻组的程序pine而来。语法pico [-bdefghjkmqtvwxz][-n][-o][-r][-s][][文件]参数说明&#xff1a;-b 开启置换的功能。-d 开启删除的功能。…

【Hihocoder - offer编程练习赛93 套题题解】交错01串(贪心,暴力)方格矩阵高度(模拟)数对(STLmultiset)修整土地(网络流)

A&#xff1a; 题干&#xff1a; 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi要将一个01串S传输给小Ho&#xff0c;由于S非常长&#xff0c;所以小Hi决定用长度为N的2个数组A [A1, A2, ..., AN]和B [B1, B2, ..., BN]表示S。 具体来讲&#xff0c;是…

linux防火墙配置连接atlas,ATLAS在ubuntu下的安装使用

1, 根据atlas的安装文档, 首先要switch off cpu throttling.在Ubuntu系统上要首先安装cpufrequtils和cpufreqd这两个包, 也许还要安装powernowd包,然后执行sudo /usr/bin/cpufreq-selector –g. 不过幸运的是, 我在server上安装的时候发现cputhrottling已经disable了(否则在con…

【CodeForces - 545 ABCDE套题训练题解】贪心, 构造,模拟,dp,最短路树(Dijkstra+变形)

A&#xff1a; 题干&#xff1a; Input The first line contains integer n (1 ≤ n ≤ 100) — the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there ar…

linux搜索pdf文件,桌面应用|如何使用 pdfgrep 从终端搜索 PDF 文件

诸如 grep 和 ack-grep 之类的命令行工具对于搜索匹配指定正则表达式的纯文本非常有用。但是你有没有试过使用这些工具在 PDF 中搜索&#xff1f;不要这么做&#xff01;由于这些工具无法读取PDF文件&#xff0c;因此你不会得到任何结果。它们只能读取纯文本文件。顾名思义&…

【CodeForces - 546C 】Soldier and Cards (模拟)

题干&#xff1a; Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, its possible that they have different number of cards. Th…

linux wifi 蓝牙冲突,linux 下 无线 wifi 蓝牙 无法启用

linux 下 无线 wifi 蓝牙 无法启用装了Debian squeeze 后发现无线不能打开首先想到的是装驱动于是在wiki.debian.org上查了下以重新装了下驱动#aptitude install firmware-b43-installler#modprobe b43# iwconfiglo no wireless extensions.eth0 no wireless exten…

Linux中wait接口用于延时,linux2.6驱动编写参考

1、 使用新的入口必须包含 module_init(your_init_func);module_exit(your_exit_func);老版本&#xff1a;int init_module(void);void cleanup_module(voi);2.4中两种都可以用&#xff0c;对如后面的入口函数不必要显示包含任何头文件。2、 GPLMODULE_LICENSE("Dual BSD/…