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个线程处理完成后,记录花费的时间,需要考虑的 ...
随机推荐
- 解决Linux终端乱码的两则例子
现象描述 我们先来说一下出现乱码的原因. 例子 先举个实际的例子,我们一般通过ssh远程到服务器上进行操作.当在终端上执行一些有输出的任务时,有可能会遇到乱码,特别是输出中有中文时. 比如,我登陆上o ...
- [HDFS_add_3] HDFS 机架感知
0. 说明 HDFS 副本存放策略 && 配置机架感知 1. HDFS 的副本存放策略 HDFS 的副本存放策略是将一个副本存放在本地机架节点上,另外两个副本放在不同机架的不同节点上 ...
- tkinter内嵌Matplotlib系列(一)之解读官网教材
目录 目录 前言 (一)小目标 1.首页卷面: 2.绘制一条函数曲线: 3.绘制多条曲线: (二)官方教材 1.对GUI框架的支持: 2.内嵌于tkinter的说明文档: (三)对官方教程的解读 目录 ...
- January 28th, 2018 Week 05th Sunday
I wish you all I ever wanted for you, I wish you the best. 我希望你不负我的期望,愿你一切安好. I hope I can live up t ...
- 解决Chunkize warning while installing gensim问题
问题: UserWarning: detected Windows; aliasing chunkize to chunkize_serial warnings.warn("detected ...
- swift class的动态派发
一.测试代码 class BaseCallClass{ func NormalCall(){} @objc func OcCall(){} @objc dynamic func OcDynamicCa ...
- centos7下安装docker(13.3volume生命周期管理)
本章讨论:volume的备份,恢复,迁移和销毁 1.备份 通过前面的大量的实验,我们知道volume 是依赖host存在的,是host中的文件或目录,所以volume 的备份实际是对文件系统的备份. ...
- P2347 砝码称重 (01背包)
题目描述 设有 1g1g1g . 2g2g2g . 3g3g3g . 5g5g5g . 10g10g10g . 20g20g20g 的砝码各若干枚(其总重 ≤1000 \le 1000≤1000 ), ...
- python3 day02 大纲
一. 格式化输出 %s 字符串的占位 %d 数字的占位 digit %f 浮点数 字符串 % (数据) 模板字符串(3.5) # username = "admin"# passw ...
- centos7搭建filebeat
filebeat的环境搭建 cd /home/elk wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.2.4 ...