Codeforces 1065C make It Equal (differential + greedy)

Source: Internet
Author: User

Test instructions: N Tower, the first tower is composed of $h_i$ cube, each time can be cut to a height of more than H K Cube, ask you to cut the minimum number of times, you can make all tower height equal

K>=n, N<=2e5

Idea: Differential statistics each height I have the number of blocks nh[i], and then from high to low greedy cut on the line

Code:

#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>#defineFST First#defineSC Second#definePB Push_back#defineMem (A, B) memset (A,b,sizeof (a))#defineLson l,mid,root<<1#defineRson mid+1,r,root<<1|1#defineLC Root<<1#defineRC Root<<1|1#defineLowbit (x) ((x) & (-X))using namespaceStd;typedefDoubleDb;typedefLong DoubleLdb;typedefLong Longll;typedef unsignedLong LongUll;typedef pair<int,int>Pi;typedef pair<ll,ll>PLL;ConstDB EPS = 1e-6;Const intMoD =100003;Const intMAXN = 2e5+ -;Const intMAXM = 2e5+ -;Constll inf =0x3f3f3f3f3f3f3f3f;ConstDB PI = ACOs (-1.0);intNH[MAXN];intMain () {intN;ll m; scanf ("%d%lld", &n, &m); intvol =0;  for(inti =1; I <= N; i++){        intC; scanf ("%d", &c); nh[0]++;nh[c+1]--; }     for(inti =1; I <= MAXN; i++) {Nh[i]+=nh[i-1]; }    intTMP =0; intAns =0;  for(inti = MAXN; I >=0; i--){        if(nh[i]==n) Break; if(tmp+nh[i]>m) {tmp=Nh[i]; Ans++; }        Elsetmp+=Nh[i]; }    if(tmp>0) ans++; printf ("%d", ans); return 0;}

Codeforces 1065C make It Equal (differential + greedy)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.