题目大意:$n$列箱子,横向消除,一次可以把一行及以上的所有箱子消除,但是一次最多只可以消除$k$个,求最少用几次把箱子的高度变成一样

题解:贪心,求出比一个高度高的有几个箱子,消除即可

卡点:代码改了一次,结尾处理部分忘记改了

 

C++ Code:

#include <cstdio>
#include <algorithm>
#define maxn 200010
inline int max(int a, int b) {return a > b ? a : b;}
inline int min(int a, int b) {return a < b ? a : b;} int ans;
int n, M, m = maxn, k, s[maxn];
int v[maxn], pre[maxn], num[maxn];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1, x; i <= n; i++) scanf("%d", &x), v[x]++, m = min(m, x), M = max(M, x);
for (int i = M; i >= m; i--) {
num[i] = num[i + 1] + v[i];
pre[i] = pre[i + 1] + num[i];
if (pre[i] > k) ans++, pre[i] = num[i];
}
if (pre[m] > n) ans++;
printf("%d\n", ans);
return 0;
}

  

[CF1065C]Make It Equal的更多相关文章

  1. [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

  2. [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等

    Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...

  3. [LeetCode] Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  4. Equal Sides Of An Array

    参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...

  5. Int,Long比较重使用equal替换==

    首先,==有很多限制,如Integer 类型的值在[-128,127] 期间,Integer 用 “==”是可以的(参考),超过范围则不行,那么使用equal则代替则完全ok public stati ...

  6. 无法解决 equal to 操作中 "SQL_Latin1_General_CP1_CI_AS" 和 "Chinese_PRC_CI_AS"

    无法解决 equal to 操作中 "SQL_Latin1_General_CP1_CI_AS" 和 "Chinese_PRC_CI_AS" 之间 2011-0 ...

  7. LeetCode Minimum Moves to Equal Array Elements II

    原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ 题目: Given a non-empt ...

  8. LeetCode Minimum Moves to Equal Array Elements

    原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements/ 题目: Given a non-empty i ...

  9. conflict between "Chinese_PRC_CI_AI" and "Chinese_PRC_CI_AS" in the equal to operation

    在SQL SERVICE做关联查询的时候遇到了"conflict between "Chinese_PRC_CI_AI" and "Chinese_PRC_CI ...

随机推荐

  1. React学习(4)——向服务器请求数据并显示

    本文中涉及到的技术包括:node.js/express服务器的搭建.fetch发送数据请求. 在之前的几篇文章中,介绍了如何搭建基础的React项目,以及一些简单知识,现在,我们还需要掌握如何用Rea ...

  2. I/O流、ZIP文档

    1) ZIP文档通常以压缩格式存储一个或多个文档.在Java中可以用ZipInputStream读入ZIP文档(即解压文件流),用ZipOutputStream写入ZIP文档(即压缩文件流),无论解压 ...

  3. Windows 10 登录界面的背景图片地址

    C:\Users\******\appdata\Local\Packages\Microsoft.Windows.ContentDeliveryManager_********\LocalState\ ...

  4. python 迭代器 和生成器

    迭代器 # 双下方法 # print([1].__add__([2])) # print([1]+[2]) # 迭代器 # l = [1,2,3] # 索引 # 循环 for # for i in l ...

  5. 008---re正则模块

    re正则模块 字符串的匹配规则 匹配模式 re.match() re.search() re.findall() re.split() re.sub() 元字符 print('------------ ...

  6. WPF 构建无外观(Lookless)控件

    原文:WPF 构建无外观(Lookless)控件 构建一个用户可以使用Template属性设置外观的WPF控件需要以下几步 1.继承自System.Windows.Controls.Control 2 ...

  7. 面试官常问的10个Linux问题

    1.如何暂停一个正在运行的进程,把其放在后台(不运行)? 为了停止正在运行的进程,让其再后台运行,我们可以使用组合键Ctrl+Z. 2.什么是安装Linux所需的最小分区数量,以及如何查看系统启动信息 ...

  8. 【APUE】Chapter4 File and Directories

    4.1 Introduction unix的文件.目录都被当成文件来看待(vi也可以编辑目录):我猜这样把一起内容都当成文件的原因是便于统一管理权限这类的内容 4.2 stat, fstat, fst ...

  9. iOS-合成图片(长图)

    合成图片 直接合成图片还是比较简单的,现在的难点是要把,通过文本输入的一些基本数据也合成到一张图片中,如果有多长图片就合成长图. 现在的实现方法是,把所有的文本消息格式化,然后绘制到一个UILable ...

  10. OpenCV入门:(四:混合两张图片)

    1. 原理 对两张图片使用如下公式可以得到两张图片的混合图片, 其中f0(x),f1(x)分别是图片1和图片2同一位置的像素点. 2. OpenCV中的AddWeight函数 函数和参数说明: ) s ...