C. Make It Equal
链接
[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的更多相关文章
- [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 ...
- why happen "WaitHandles must be less than or equal to 64"
一.背景: 在一个项目中碰到大数据插入的问题,一次性插入20万条数据(SQL Server),并用200个线程去执行,计算需要花费多少时间,因此需要等200个线程处理完成后,记录花费的时间,需要考虑的 ...
随机推荐
- 阿里云上安装pip3(Ubuntu)
安装pip3: 这个简单啊,到网上下载get-pip.py的脚本,然后scp到你的阿里云服务器上,python3 get-pip.py即可. 如果不会scp,哈哈,按照下面的几步: wget http ...
- VS2015 无法启动 IIS Express Web 服务器 解决方案
VS2015 IIS Express 无法启动Web 解决方案 [亲测已成功] 1.我的电脑—管理—事件查看器—Windows日志—应用程序: 详细信息会提示你:[模块 DLL C:\Program ...
- Lua 与 C 交互之UserData(4)
lua作为脚本于要能够使用宿主语言的类型,不管是宿主基本的或者扩展的类型结构,所以Lua提供的UserData来满足扩展的需求.在Lua中使用宿主语言的类型至少要考虑到几个方面: 数据内存 生命周期 ...
- BeanFactory中Bean的生命周期
Bean的生命周期图解 集体过程如下: 当调用者通过getBean(beanName)向容器请求某一个Bean时,如果容器注册了org.springframework.beans.factory.co ...
- CSS Hack的一些知识
测试环境:Windows7 主要测试:IE6.IE7.IE8.Fire Fox3.5.6 次要测试:Chrome4.0.Opera10.10.Safari4.04.360浏览器3.1 为了能够让多个H ...
- java注释讲解
注释简单的来说就是一种说明,不能被当成执行语句执行.做为一名程序员,但我们在写代码时是顺着思路写下去的.写代码好比就是在做题.当你在做的时候你脑海时的思路很清晰,会想到用一些特殊的方法来解决当前的问题 ...
- 怎么配置 Oracle 侦听器来使用SQL操作ST_Geometry
关于这个内容,其实从ArcSDE9.2推出ST_Geometry就让用户感到很有吸引力,而且特别是在ArcSDE9.3之后,用户使用SQL操作ST_geometry越来越多,但是在配置Oracle监听 ...
- Luogu P3462 [POI2007]ODW-Weights
题目描述 While moving to a new compound the Byteotian Institute of Experimental Physics has encountered ...
- WPFの数据源事件变更通知
如果数据绑定的目标是TextBox元素的Text属性,那么默认会使用双向绑定(Mode.TwoWay),此时用户可以通过更改TextBox元素Text属性的值从而更新源属性信息,但是如果在程序代码中更 ...
- 离线安装Cloudera Manager 5和CDH5(最新版5.9.3) 完全教程(四)数据库安装(单节点)
一.卸载CentOS自带的MySQL 1.1 查看之前是否安装过mysql [root@master mysql]# rpm -qa|grep -i mysql mysql-libs--.el6.x8 ...