[CF1065C]Make It Equal
题目大意:$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的更多相关文章
- [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 ...
- [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 ...
- [LeetCode] Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- Equal Sides Of An Array
参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...
- Int,Long比较重使用equal替换==
首先,==有很多限制,如Integer 类型的值在[-128,127] 期间,Integer 用 “==”是可以的(参考),超过范围则不行,那么使用equal则代替则完全ok public stati ...
- 无法解决 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 ...
- LeetCode Minimum Moves to Equal Array Elements II
原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ 题目: Given a non-empt ...
- LeetCode Minimum Moves to Equal Array Elements
原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements/ 题目: Given a non-empty i ...
- 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 ...
随机推荐
- 初次了解MVC框架模式
MVC框架:即Model.View.Controller即模型.视图.控制器. View层是界面,Model层是业务逻辑,Controller层用来调度View层和Model层,将显示界面和业务逻辑合 ...
- MFC下的DLL编程学习
1.DLL库与LIB库对比: 静态链接库Lib(Static Link Library),是在编译的链接阶段将库函数嵌入到应用程序的内部.如果系统中运行的多个应用程序都包含所用到的公共库函数,则必然造 ...
- vuex组件 vuex-persistedstate
vuex用于管理项目中的全局状态,但是我们一刷新vuex中保存的全局状态就会被全部初始化,虽然我们也可以同事缓存到storage中做两步操作,但是vuex-persistedstate组件已经帮我们完 ...
- Python特别low的一个文字游戏
闲来无事 ,调侃舍友的游戏 import os class Role(): def __init__(self,name,sex,fighting): self.name=name self.sex= ...
- 05 redis(进阶)
redis 阶段一.认识redis 1.什么是redis Redis是由意大利人Salvatore Sanfilippo(网名:antirez)开发的一款内存高速缓存数据库.Redis全称为:Remo ...
- Java——自动生成30道四则运算---18.09.27
package chuti;import java.io.PrintWriter;import java.util.Scanner;import java.io.FileNotFoundExcepti ...
- 博科brocade光纤交换机alias-zone的划分-->实操案例
一,图形化操作 光纤交换机作为SAN网络的重要组成部分,在日常应用中非常普遍,本次将以常用的博科交换机介绍基本的配置方法. 博科300实物图: 环境描述: 如上图,四台服务器通过各自的双HBA卡连接至 ...
- wnds更新为1.0
重画了外观,增加了若干功能,已经上传到码云 https://gitee.com/alan0405/wnds
- 1 http协议
1.四层模型 + 2.socket 3.http协议 4. HTTP请求 跟踪了新浪的首页,我们来总结一下HTTP请求的流程: 3.1.1 步骤1:浏览器首先向服务器发送HTTP请求,请求包括: 方法 ...
- win10 java环境变量配置
首先,你应该已经安装了 Java 的 JDK 了(如果没有安装JDK,请跳转到此网址:http://www.oracle.com/technetwork/java/javase/downloads/i ...