Codeforces 1065C Make It Equal (差分+贪心)
题意:n个塔,第i个塔由$h_i$个cube组成,每次可以切去某高度h以上的最多k个cube,问你最少切多少次,可以让所有塔高度相等
k>=n, n<=2e5
思路:差分统计每个高度i有的方块数nh[i],然后从高到低贪心的切就行了
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
//#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = ;
const int maxn = 2e5+;
const int maxm = 2e5+;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const db pi = acos(-1.0); int nh[maxn];
int main() {
int n;ll m;
scanf("%d %lld", &n, &m);
int vol = ;
for(int i = ; i <= n; i++){
int c;
scanf("%d", &c);
nh[]++;nh[c+]--; }
for(int i = ; i <= maxn; i++){
nh[i]+=nh[i-];
}
int tmp = ;
int ans = ;
for(int i = maxn; i >= ; i--){
if(nh[i]==n)break;
if(tmp+nh[i]>m){
tmp=nh[i];
ans++;
}
else tmp+=nh[i];
}
if(tmp>)ans++;
printf("%d", ans);
return ;
}
Codeforces 1065C Make It Equal (差分+贪心)的更多相关文章
- F - Make It Equal CodeForces - 1065C
题目大意:有n座塔,塔高h[i],每次给定高度H对他们进行削切,要求每次削掉的所有格子数不能超过k个,输出最少削几次才能使所有塔的高度相同. 思路一:差分+贪心 对于每一个高度h,用一个数组让1~h的 ...
- Codeforces 437C The Child and Toy(贪心)
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- codeforces 1017C - Cloud Computing 权值线段树 差分 贪心
https://codeforces.com/problemset/problem/1070/C 题意: 有很多活动,每个活动可以在天数为$[l,r]$时,提供$C$个价格为$P$的商品 现在从第一天 ...
- Codeforces.GYM101612E.Equal Numbers(贪心)
题目链接 \(Description\) 给定\(n\)个数,每次可以将任意一个数乘上任意一个正整数. 求\(k\)次操作后,数列中数的种类最少可以是多少.对每个\(0\leq k\leq n\)输出 ...
- Codeforces Round #479 (Div. 3) C. Less or Equal (排序,贪心)
题意:有一个长度为\(n\)的序列,要求在\([1,10^9]\)中找一个\(x\),使得序列中恰好\(k\)个数满足\(\le x\).如果找不到\(x\),输出\(-1\). 题解:先对这个序列排 ...
- Educational Codeforces Round 61 C 枚举 + 差分前缀和
https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...
- CodeForces 1000B Light It Up(贪心、思维)
https://codeforces.com/problemset/problem/1000/B 题意: 一个模拟思维题.就是有一盏灯,0时刻开着.n次操作,你可以在其中加入一次操作(或者不加),操作 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- ffmpeg参数编码大全
ffmpeg version N-49044-g89afa63 Copyright (c) 2000-2013 the FFmpeg developers built on Jan 19 2013 2 ...
- Go Web 编程之 Hello World
概述 计划写一个讲 Go Web 编程的系列文章.从基于 net/http 包编写 Go Web 程序开始,讲述处理器,请求,响应等基础知识.然后到框架的使用.中间会穿插一些源码的分析.最后做一个实战 ...
- python 多进程处理图像,充分利用CPU
默认情况下,Python程序使用一个CPU以单个进程运行.不过如果你是在最近几年配置的电脑,通常都是四核处理器,也就是有8个CPU.这就意味着在你苦苦等待Python脚本完成数据处理工作时,你的电脑其 ...
- JSON的学习与使用
.katex { display: block; text-align: center; white-space: nowrap; } .katex-display > .katex > ...
- VMware Workstation CentOS7 Linux 学习之路(3)--.net coreWeb部署
1.首先创建一个文件夹,命名为core mkdir core cd core 2.我这里用FlashFXP连接Linux 把我发布的项目上传到CentOS7的core文件夹下 此时我输入命令 dotn ...
- python 打印乘法表
for i in range(1, 10): for j in range(1, i+1): print('%s * %s = %s' % (i, j, i*j), end=' ') print('' ...
- (转)GET来的漏洞
转自呆子不开口在wooyun知识库的文章 0x00 前言 这篇文章主要讲目前互联网上get方法被不规范使用带来的一些安全漏洞.其中重点会讲get请求在账号登陆体系中被滥用的场景和攻击方式. 0x01 ...
- Installing PyCharm
Installing PyCharm| # ...
- git recommend(alive)
初始化并跟踪远程分支: echo "# test" >> README.mdgit initgit add README.mdgit commit -m "f ...
- Redis(七):set/sadd/sismember/sinter/sdiffstore 命令源码解析
上两篇我们讲了hash和list数据类型相关的主要实现方法,同时加上前面对框架服务和string相关的功能介绍,已揭开了大部分redis的实用面纱. 现在还剩下两种数据类型: set, zset. 本 ...