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; ...
随机推荐
- BZOJ5322 [Jxoi2018]排序问题 【贪心】
题目链接 BZOJ5322 题解 意思就是使有序的排列尽量少 就是使相同的数尽量少 然后大力贪心即可 #include<algorithm> #include<iostream> ...
- CENSORING
CENSORING 题目描述 FJ为它的奶牛订阅了很多杂志,balabala.......,其中有一些奶牛不宜的东西(比如如何煮牛排). FJ将杂志中所有的文章提取出来组成一个长度最多为10^5的字符 ...
- 【BZOJ 2434】 [Noi2011]阿狸的打字机 fail树+树状数组
就是考了一个fail树的神奇应用我们建出fail树之后,发现我们就是在求y到根的路径上所有的点在以x为根的子树里的个数,这个我们离线后用树状数组+dfs序即可解决 #include <cstdi ...
- Dubbo入门介绍---搭建一个最简单的Demo框架
Dubbo入门---搭建一个最简单的Demo框架 置顶 2017年04月17日 19:10:44 是Guava不是瓜娃 阅读数:320947 标签: dubbozookeeper 更多 个人分类: D ...
- Good Substrings CodeForces - 271D
You've got string s, consisting of small English letters. Some of the English letters are good, the ...
- springboot与dubbo结合
转:http://www.cnblogs.com/Alandre/p/6490142.html 写的很好! 本文提纲 一.为啥整合 Dubbo 实现 SOA 二.运行 springboot-dubb ...
- wait , notify 模拟 Queue
package com.itdoc.multi.sync009; import java.util.LinkedList; import java.util.concurrent.TimeUnit; ...
- MUI -- plus初始化原理及plus is not defined,mui is not defined 错误汇总
不要在没有plus和mui的环境下调用相关API 普通浏览器里没有plus环境,只有HBuilder真机运行和打包后才能运行plus api. 在普通浏览器里运行时plus api时控制台必然会输出p ...
- centos yum 安装 mysql
centos7下使用yum安装mysql 时间:2015-03-07 21:26:20 阅读:87445 评论:0 收藏:1 [点我收藏+] 标签: Cen ...
- 【BZOJ2326】【HNOI2011】数学作业 [矩阵乘法][DP]
数学作业 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description Input 输入文件只有一行为用空 ...