CF&&CC百套计划1 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[]; int main()
{
int n,m,c,x;
scanf("%d%d%d",&n,&m,&c);
int mid=c>>;
int sum=;
while(m--)
{
scanf("%d",&x);
if(x<=mid)
{
for(int i=;;++i)
{
if(!a[i])
{
a[i]=x;
sum++;
printf("%d\n",i);
break;
}
else if(a[i]>x)
{
a[i]=x;
printf("%d\n",i);
break;
}
}
}
else
{
for(int i=n;;--i)
{
if(!a[i])
{
a[i]=x;
sum++;
printf("%d\n",i);
break;
}
else if(x>a[i])
{
a[i]=x;
printf("%d\n",i);
break;
}
}
}
fflush(stdout);
if(sum==n) return ;
}
}
1 second
256 megabytes
standard input
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.
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.
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.
2 4 4
2
1
3
1
2
2
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.
CF&&CC百套计划1 Codeforces Round #449 B. Ithea Plays With Chtholly的更多相关文章
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle
http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
随机推荐
- 第一次spring冲刺第3、4天
11月14至15日 因为忙于项目的谈论与探究,以及周末的活动变动,使得博客没有时间提交上去,这里补交. 这两天,主要是应对于市场的探究做谈论,我们主要面对什么类型的客户,以及他们最需要的是什么等话题做 ...
- PyCharm 配置远程python解释器和在本地修改服务器代码
PyCharm 配置远程python解释器和在本地修改服务器代码 最近在学习机器学习的过程中,常常需要将本地写的代码传到GPU服务器中,然后在服务器上运行.之前的做法一直是先在本地写好代码,然后通过F ...
- ps -aux 命令下的前几行内容解释 与 top命令下的前几行内容解释
系统进程分为5种不同的状态: R(运行):正在运行或在运行队列中等待 S(中断):休眠中,在等待某个条件的形成或接受到信号 D(不可中断):收到信号不唤醒和不可运行.进程必须等待直到有中断发生 Z(僵 ...
- Linux网卡配置文件路径是什么?要使服务器上外网,必须满足的条件有哪些?需要配置什么?
Linux网卡配置文件路径是什么?要使服务器上外网,必须满足的条件有哪些?需要配置什么? 答: 网卡配置文件路径:/etc/sysconfig/network-scripts/ifcfg- ...
- c语言文法定义
<程序>→<外部声明>|<程序><外部声明> <外部声明>→<函数定义>|<声明> <函数定义>→< ...
- try…catch 结构
try…catch 结构 一旦发生错误,程序就中止执行了.JavaScript 提供了try...catch结构,允许对错误进行处理,选择是否往下执行. try { throw new Error(' ...
- 【转】正确的 Composer 扩展包安装方法
简单解释 composer install - 如有 composer.lock 文件,直接安装,否则从 composer.json 安装最新扩展包和依赖: composer update - 从 c ...
- 抽奖系统 random()
random() 方法可返回介于 0 ~ 1 之间的一个随机数. document.write(parseInt(10*Math.random())); //输出0-10之间的随机整数document ...
- poj 3254(状态压缩DP)
poj 3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...
- 自定义smokeping告警(邮件+短信)
前段时间接到公司IT同事需求,帮助其配置smokeping的告警功能,之前配置的姿势有些问题,告警有些问题,现在调试OK,在此将关键配置点简单记录下. 关键的配置项主要有: 定义告警规则并配置将告警信 ...