Codeforces Round #449 (Div. 2) D(思维)
来源:互联网 发布:没卡怎么在淘宝买东西 编辑:程序博客网 时间:2024/06/06 05:07
Description
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
input2 4 4213output122
题目大意
有n张纸片,每次给定一个数,由你决定将这个数写到哪张纸片上,并在m次轮回中能实现所有的数能够满足非递减序列。给定的数的范围为[1,c],对于每次给定的数,输出对应的选择的纸片的位置,一旦满足非递减序列,终止程序。
解题思路
由题意可知,
代码实现
#include<bits/stdc++.h>using namespace std;#define maxn 1007#define maxx 0x3f3f3fint a[maxn];int n;bool judge(){ bool flag=false; for(int i=1; i<n; i++) if(a[i]>a[i+1]||a[i]==0) { flag=true; break; } if(a[n]==0) flag=true; return flag;}int main(){ ios::sync_with_stdio(false); int m,c,t,i; cin>>n>>m>>c; a[1]=maxx; if(n==1) { cin>>t; cout<<"1"<<endl; return 0; } else { while(judge()) { cin>>t; if(t*2<=c) { for(i=1; i<n; i++) if(a[i]>t||a[i]==0) break; cout<<i<<endl; fflush(stdout); a[i]=t; } else { for(i=n; i>1; i--) if(a[i]<t||a[i]==0) break; cout<<i<<endl; fflush(stdout); a[i]=t; } } } return 0;}
- Codeforces Round #449 (Div. 2) D(思维)
- Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 思维
- Codeforces Round #377(Div. 2)D.Exams(二分+思维)
- Codeforces Round #408 (Div. 2) D.Police Stations【Bfs+思维】
- Codeforces Round #410 (Div. 2) D. Mike and distribution 思维
- Codeforces Round #408 (Div. 2) D.Police Stations【Bfs+思维】
- Codeforces Round #297 (Div. 2) D - Arthur and Walls [思维]【思维】
- Codeforces Round #397(Div. 1 + Div. 2 combined)D. Artsem and Saunders【思维+乱搞】
- Codeforces Round #378 (Div. 2) && codeforces 733D(思维枚举)
- Codeforces Round #449 (Div. 2) B. Chtholly's request (思维
- Codeforces Round #256 (Div. 2)思维训练
- Codeforces Round #262 (Div. 2)思维训练
- Codeforces Round #353 (Div. 2) C 思维
- Codeforces Round #221 (Div. 2) D. Maximum Submatrix 2 (思维题)
- Codeforces Round #308 (Div. 2) —— D (思维题)
- Codeforces Round #387(Div. 2)D. Winter Is Coming【思维+dp】
- Codeforces Round #386(Div. 2)D. Green and Black Tea【思维+构造】
- Codeforces Round #388(Div. 2)D. Leaving Auction【二分+思维】好题~
- 拓扑排序
- 关于TP框架隐藏index.php
- CentOS7 yum安装mongodb
- 在Kali linux下安装XAMPP并搭建DVWA遇到的问题及解决办法
- itop4412 uboot 学习详细记录(二丶Exynos4412 uboot的组成)
- Codeforces Round #449 (Div. 2) D(思维)
- 【安全牛学习笔记】OWASP_ZAP
- springmvc下的Token设计
- 前端移动端适配方法
- 如何使用Rust提高Ruby性能
- IDA 使用技巧
- POST请求慎用301 Moved Permanently
- 2017主要服务产品体系
- jquery event.target 事件委托