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] 表示第 ...
随机推荐
- Python开发【第五篇】迭代器、生成器、递归函数、二分法
阅读目录 一.迭代器 1. 迭代的概念 #迭代器即迭代的工具(自定义的函数),那什么是迭代呢? #迭代:指一个重复的过程,每次重复都可以称之为一次迭代,并且每一次重复的结果是下一个迭代的初始值(例如: ...
- 动态生成CheckBox(Winform程序)
在做用户权限设置功能时,需要做一个动态生成权限列表的功能.(笔记.分享) //1.清空权限控件组的默认控件 panelPermissions.Controls.Clear(); _groupBoxLi ...
- CefSharp,Winform程序中加载web网页
源码地址:https://github.com/cefsharp/CefSharp 开源相关:https://github.com/cefsharp/CefSharp/tree/master/CefS ...
- AT89C51的内部4K flash,
AT89C51的内部4K flash, 是用来下载程序代码的,程序运行时只能做读取数据操作,不能写入.单片机断电时需要候保存数据,可以选择 带EEPROM的单片机 就可以,如STC 系列的单片机有内部 ...
- C++派生类构造函数调用顺序(详解)
我们来看下面一段代码: class B1 { public: B1(int i) {cout<<"constructing B1 "<<i<<e ...
- 【OSG】将显示的图形窗口化
窗口化原理 有时为了方便控制场景渲染,需要设置一个合适的图形环境窗口(即窗口化). 创建图形环境的主要步骤如下: (1)通过WindowingSystemInterface类得到系统窗口接口,该系统接 ...
- No module named 'MySQLdb' python3.6 + django 1.10 + mysql 无法连接
学习python 连接mysql数据库的时候遇到了问题 首先安装mysql: 工具栏 ===>file ==> default settings==>Project Interpre ...
- 小菜菜mysql练习50题解析——数据准备
附上数据准备: 学生表 create table Student(SId varchar(10),Sname varchar(10),Sage datetime,Ssex varchar(10)); ...
- PGM学习之四 Factor,Reasoning
通过上一篇文章的介绍,我们已经基本了解了:Factor是组成PGM模型的基本要素:Factor之间的运算和推理是构建高维复杂PGM模型的基础.那么接下来,我们将重点理解,Factor之间的推理(Rea ...
- 【刷题】洛谷 P3872 [TJOI2010]电影迷
题目描述 小A是一个电影迷,他收集了上百部的电影,打算从中挑出若干部在假期看完.他根据自己的口味和网上的介绍,对每部电影X都打了一个分数vX,表示自己喜欢的程度.这个分数的范围在-1000至1000之 ...