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 ;
}
}
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.

CF&&CC百套计划1 Codeforces Round #449 B. Ithea Plays With Chtholly的更多相关文章

  1. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

    http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...

  2. 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> # ...

  3. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  4. 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的数 维护 ...

  5. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding

    http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...

  6. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

  7. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation

    http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...

  8. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik

    http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...

  9. 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] 表示第 ...

随机推荐

  1. java编程的一些注意事项

    下面是参考网络资源和总结一些在java编程中尽可能做到的一些地方 1.尽量在合适的场合使用单例 使用单例可以减轻加载的负担,缩短加载的时间,提高加载的效率,但并不是所有地方都适用于单例,简单来说,单例 ...

  2. Ubuntu恢复被误删的文件

    主要内容转载自博客:https://blog.csdn.net/YLD10/article/details/80241160 写在前面,该方法只能用于误删的文件,若文件被覆盖,则无法恢复. 1.下载工 ...

  3. JAVA自学日记——Part Ⅱ

    今天学习了类与对象,其中关于this关键字的用法,static静态变量与静态方法,以及引用传递需要特别注意一下. 首先是引用传递: 在本段程序中可以通过进行外部对类对象的属性赋值来更改,同时也可以通过 ...

  4. Prism6下的MEF:第一个Hello World

    最近看书比较多,正好对过去几年的软件开发做个总结.写这个的初衷只是为了简单的做一些记录. 前言 复杂的应用程序总是面临很多的页面之间的数据交互,怎样创建松耦合的程序一直是多数工程师所思考的问题.诸如依 ...

  5. Activity设置背景透明之开发坑

    Activity设置背景透明的常规方法 方法一.在Manifest.xml中,直接在需要设置的Activity中添加主题样式: Android:theme="@android:style/T ...

  6. beta发布简评

    第一组:新蜂小组 题目:俄罗斯方块 评论:主体功能已经完成,可以流畅的进行游戏,无论效果或是功能都实现的很好. 第二组:Nice团队 题目:约跑APP(约吧) 评论:作为应用,想法创意很好:功能实现上 ...

  7. node下的跨域传递cookie

    研究背景: 最近有一位朋友找工作,需要面试,涉及到面试就涉及面试题,于是我想起来鄙人之前面试被问到的一个跨域传递cookie的问题.搜索了相关资料,但自己不敲一下肯定是不足以让人信服的. 我用node ...

  8. TP5 助手函数与TP3.2单字母函数

    一.TP5 助手函数 助手函数 描述 abort 中断执行并发送HTTP状态码 action 调用控制器类的操作 cache 缓存管理 config 获取和设置配置参数 controller 实例化控 ...

  9. Art & Material

    Art(Android runtime)模式伴随Android 4.4发布.相对于Dalvik模式来说,Art模式改善了Android程序的性能. Material Design伴随Android 5 ...

  10. Jquery插件收集【m了慢慢学】

    1. Simple Effects for Drop-Down Lists 一个jQuery插件用于将普通的select控件转成一个带有一些简单扩展效果的下拉列表. 2. X-editable 这个插 ...