Codeforces #449 Div2 D
#449 Div2 D
题意
交互式类题目。
起始有 n 张纸,会给出 m 次数字 p (\(1 \leq p \leq c\)),每次可选择一张纸,并在纸上写上这个数字,如果纸上已经存在数字,会覆盖掉原来的数字。问不超过 m 次能否使得所有纸上都有数字且不降序排列。
分析
这类想法题挺常见的了,观察数据范围 $ \left \lceil \frac{c}{2} \right \rceil \cdot n \leq m$,我们可以这么理解, \(n\) 张纸,每张最多变 $ \left \lceil \frac{c}{2} \right \rceil $ 次。
考虑对于小于 \(\left \lceil \frac{c}{2} \right \rceil\) 的数字我们从左往右放,否则从右往左放,且保持数字一直有序。考虑最坏的情况,若依次给出数字 \([\left \lceil \frac{c}{2} \right \rceil, c]\) ,我们都只能填到最右边的纸上,需要改变 \(\left \lceil \frac{c}{2} \right \rceil\) 次,其它纸类似。所以对于题目所给出的数据范围我们的贪心策略是有效的。
code
#include<bits/stdc++.h>
using namespace std;
int a[1111];
int main() {
int n, m, c;
cin >> n >> m >> c;
int cnt = 0;
c = c / 2;
while(1) {
int p, pos;
cin >> p;
if(p <= c) {
for(int i = 1; i <= n; i++) {
if(!a[i] || a[i] > p) {
if(!a[i]) cnt++;
a[i] = p;
pos = i;
break;
}
}
} else {
for(int i = n; i >= 1; i--) {
if(!a[i] || a[i] < p) {
if(!a[i]) cnt++;
a[i] = p;
pos = i;
break;
}
}
}
cout << pos << endl;
fflush(stdout);
if(cnt == n) break;
}
return 0;
}
Codeforces #449 Div2 D的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
随机推荐
- P1712 [NOI2016]区间
题目描述 在数轴上有 NN 个闭区间 [l_1,r_1],[l_2,r_2],...,[l_n,r_n][l1,r1],[l2,r2],...,[ln,rn] .现在要从中选出 MM 个区 ...
- [Leetcode] Binary tree maximum path sum求二叉树最大路径和
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...
- getActionBar为null的解决以及ActionBar的Back键
http://blog.csdn.net/lincyang/article/details/46286895
- codeforces803D. Magazine Ad
D. Magazine Adtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutput ...
- DES 加密解密
[概念] 数据加密算法(Data Encryption Algorithm,DEA)是一种对称加密算法,很可能是使用最广泛的密钥系统,特别是在保护金融数据的安全中,最初开发的DEA是嵌入硬件中的.通常 ...
- Java 中request.getInputStream()和BufferedReader 和 InputStreamReader 用法
关于request.getInputStream(): http://www.cnblogs.com/steve-cnblogs/articles/5420198.html 浏览器 采用了一种编码方式 ...
- codeforces613B - Skills &&金中市队儿童节常数赛
题目传送门 本随笔写的是第二题...... 这道题方法就是搞乱....因为n较mxa小 所以枚举达到最大上限的点 然后就乱搞 代码看看咯 #include<cstdio> #include ...
- 12.22笔记(关于CALayer//Attributes//CALayer绘制图层//CALayer代理绘图//CALayer动画属性//CALayer自定义子图层//绘图pdf文件//绘图渐变效果)
12.22笔记 pdf下载文件:https://www.evernote.com/shard/s227/sh/f81ba498-41aa-443b-81c1-9b569fcc34c5/f033b89a ...
- Sequence(ST表)(洛谷P2048)
超级钢琴 知识储备 在做这道题前,我们先要了解一下ST表(一种离线求区间最值的方法) ST表使用DP实现的,其查询复杂度为O(1). 那么我们怎么用DP实现呢?? 首先,我们设立一个状态f[i][j] ...
- node导入导出的问题
node的每一个文件,都是一个域,那么里面所有的变量都不允许被外界引用,除非导出去.要使用外界的变量,也必须使用导入的方式导入进来. import 变量名 from '文件地址'//css可以直接导入 ...