思维 || Make It Equal
http://codeforces.com/contest/1065/problem/C
题意:给你n个高度分别为a[i]的塔,每次可以横着切一刀,切掉不多于k个塔,问最少切多少刀才能把塔切的都一样高(k>=n)
高度和n都在2*10^5以内
思路:既然高度在20w以内嘛 那就按高度模拟惹 然鹅该怎么模拟着实头疼了一下下
用a[i] 记录高度为i-1时,有多少个塔有高度,如果当前高度为i-1时有a[i]个塔,并且a[i]<k,那么可以去考虑下一层
用sum记录上一层之前还有多少没切,比较sum+a[i]和k的大小可以决定切不切,切的话就cnt++,剩的sum就是a[i](因为是sum+a[i]>k时切的
然后就是a[i]怎么算出来的问题了嘤嘤嘤
用了桶排序(?)和前缀和(?)类似的思想(?)←开始瞎bb
因为越往高,塔数肯定不减,输入每个高度的时候记录一下到这个高度时,塔数要-1(a[h]--), 然后a[0]=n, a[i] += a[i-1],一个个往后加就可以了
#include <stack>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = ;
const int INF = ;
int a[maxn];
int main()
{
int n, k;
scanf("%d%d", &n, &k);
int maxh = ;
for(int i = ; i <= n; i++)
{
int h;
scanf("%d", &h);
maxh = max(h, maxh);
a[h]--;
}
a[] = n;
for(int i = ; i <= maxh; i++)
a[i] += a[i-];
int cnt = , res = ;
for(int i = maxh; i >= ; i--)
{
if(a[i] == n)
{
if(res) cnt++;
break;
}
if(res + a[i] > k)
{
cnt++;
res = a[i];
}
else
res += a[i];
}
printf("%d\n", cnt);
return ;
}
思维 || Make It Equal的更多相关文章
- CF思维联系– Codeforces-988C Equal Sums (哈希)
ACM思维题训练集合 You are given k sequences of integers. The length of the i-th sequence equals to ni. You ...
- ACM思维题训练 Section A
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...
- CF 988C Equal Sums 思维 第九题 map
Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Equal Numbers Gym - 101612E 思维
题意: 给你n个数vi,你有k次操作.每一次操作你可以从n个数里面挑一个数,然后使得这个数乘于一个正整数.操作完之后,这n个数里面不同数的数量就是权值.你要使得这个值尽可能小. 题解: 如果a%b== ...
- FOJProblem 2214 Knapsack problem(01背包+变性思维)
http://acm.fzu.edu.cn/problem.php?pid=2214 Accept: 4 Submit: 6Time Limit: 3000 mSec Memory Lim ...
- Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- vue源码逐行注释分析+40多m的vue源码程序流程图思维导图 (diff部分待后续更新)
vue源码业余时间差不多看了一年,以前在网上找帖子,发现很多帖子很零散,都是一部分一部分说,断章的很多,所以自己下定决定一行行看,经过自己坚持与努力,现在基本看完了,差ddf那部分,因为考虑到自己要换 ...
- 663. Equal Tree Partition 能否把树均分为求和相等的两半
[抄题]: Given a binary tree with n nodes, your task is to check if it's possible to partition the tree ...
- 698. Partition to K Equal Sum Subsets 数组分成和相同的k组
[抄题]: Given an array of integers nums and a positive integer k, find whether it's possible to divide ...
随机推荐
- ORM取数据很简单!是吗?
简介 几乎任何系统都以某种方式与外部数据存储一起运行.大多数情况下,外部数据存储是一个关系数据库,并且在实现时通常将数据提取任务委托给某些 ORM. 尽管 ORM 包含很多 routine 代码,但是 ...
- lightoj1006【记忆化搜索(我是这么叫)】
搜索的时候记录一下,注意要long long: #include<cstdio> #include<queue> #include<map> #include< ...
- lightoj1001【简单题】
题意: 一个人的值不能超过10: #include<stdio.h> #include<queue> #include<string.h> #include< ...
- Bloomberg 的一些功能
FFLO: 查看ETF流动,注意在View点击Contries后选择Asia,查看亚洲流动. 随后对感兴趣的国家点击查看具体股票的流动 关闭Launchpad View之后再次打开: BLP 修改La ...
- Aandroid 解决apk打包过程中出现的“Certificate for <jcenter.bintray.com> doesn't match any of the subject alternative names: [*.aktana.com, aktana.com]”的问题
有时候,apk打包过程中会出现“Certificate for <jcenter.bintray.com> doesn't match any of the subject alterna ...
- UVA10140 Prime Distance【素数/数论】By cellur925
题目传送门 我们注意到,L,R是肥肠大的.........我们不可能在1s内筛出2^31内的全部质数. “上帝为你关上一扇门,同时为你打开一扇窗” 我们又注意到,R-L是肥肠比较小的,珂以从这入手解决 ...
- PAT甲级——1135 Is It A Red-Black Tree (30 分)
我先在CSDN上面发表了同样的文章,见https://blog.csdn.net/weixin_44385565/article/details/88863693 排版比博客园要好一些.. 1135 ...
- 2017 Multi-University Training Contest - Team 1 Add More Zero
Problem Description There is a youngster known for amateur propositions concerning several mathemati ...
- 如何实现序列化为json
因为需要观察对象的数据,所以寻找能自动描述对象中字段名和其值的描述类,咨询了不少人,都推荐使用json,但是json使用起来有一点额外的操作. 需要在文件中引用 using System.Web.Sc ...
- DB2 错误 54001
DB2 语句太长或者太复杂 SQLSTATE=54001 对数据库的参数的修改: db2 update db cfg for DB_NAME using STMTHEAP 4096 db2 updat ...