链接

[http://codeforces.com/contest/1065/problem/C]

题意

给你n个高度hi的塔,让你把高的部分切掉,使得最后所有塔一样高,而且每次切的高度之和不大于k

分析

从最高的塔,贪心地切到最低的塔,判断不大于k,即可

具体看代码

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h[200010];
int cnt[200010];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("in.txt","r",stdin);
ll n,k,i;
memset(cnt,0,sizeof(cnt));
cin>>n>>k;
ll x=1000000010;
ll d=0;
for(i=1;i<=n;i++)
{
cin>>h[i];
cnt[h[i]]++;
x=min(h[i],x);
d=max(d,h[i]);
}
ll sum=0,ans=0;
for(i=d;i>x;i--){
cnt[i]+=cnt[i+1];
if(sum+cnt[i]>k){
ans++;
sum=cnt[i];
}
else {
sum+=cnt[i];
}
}
cout<<ans+(sum>0?1:0)<<endl;
return 0;
}

C. 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 ...

  10. why happen "WaitHandles must be less than or equal to 64"

    一.背景: 在一个项目中碰到大数据插入的问题,一次性插入20万条数据(SQL Server),并用200个线程去执行,计算需要花费多少时间,因此需要等200个线程处理完成后,记录花费的时间,需要考虑的 ...

随机推荐

  1. 使用缓存方式优化递归函数与lru_cache

    一.递归函数的弊端 递归函数虽然编写时用很少的代码完成了庞大的功能,但是它的弊端确实非常明显的,那就是时间与空间的消耗. 用一个斐波那契数列来举例 import time #@lru_cache(20 ...

  2. MATLAB插 值 法

    MATLAB插  值  法 作者:凯鲁嘎吉 - 博客园http://www.cnblogs.com/kailugaji/ 一.实验目的 二.实验原理 三.实验程序 四.实验内容 五.解答 1. 程序 ...

  3. vue_模板渲染

    渲染 当获取到后端数据后,我们会把它按照一定的规则加载到写好的模板中,输出成在浏览器中显示的HTML,这个过程就称之为渲染. vue.js是在前端(即浏览器内)进行的模板渲染. 前后端渲染对比 前端渲 ...

  4. Vue框架的两种使用方式

    1.单页面应用:使用Vue CLI工具生成脚手架,这是最常见的使用方式,简单用模板生成一个HelloWorld Demo,可以学习Vue的SPA项目结构 2.传统多页面应用:通过script引入Vue ...

  5. (9)Python循环结构

  6. js中Math之random,round,ceil,floor的用法总结

    1.Math.random(); 结果为0-1间的一个随机数(包括0,不包括1) 2.Math.floor(num); 参数num为一个数值,函数结果为num的整数部分(返回小于等于n的最大整数). ...

  7. for-in和for-of,forEach和Map

    for-in和for-of 1. for-in循环实际是为循环”enumerable“对象而设计的,是用来循环带有字符串key的对象的. 使用for in会遍历数组所有的可枚举属性,包括原型.所以fo ...

  8. ActiveMQ安装配置及使用

    ActiveMQ介绍 ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管J ...

  9. SQL优化思路大全

    一.百万级数据库优化方案 1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断 ...

  10. vue指令相关的

    阅读目录 1.v-text 2.v-html 3.v-show 4.v-if 5.v-if vs v-show 6.v-else 7.v-for 8.v-on 9.v-bind 和 v-model 1 ...