题目
https://www.luogu.org/problemnew/show/P2827
思路
80分做法:
开一个堆(优先队列),每次找到最长的切割。
对于每回合都要长q,根据生长是相对的,我们可以视为那两条缩短了q,最后加上m*q即可
100分做法
发现此题中隐含的单调性
先被切掉的蚯蚓分成的蚯蚓一定比后切掉的蚯蚓分成的蚯蚓大
证明显然
代码
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
using namespace std;
const int N=7e6+77;
bool cmp(const int &a,const int &b)
{
return a>b;
}
priority_queue<int>ans;
int cut1[N],now[N],cut2[N];
int n,m,q,u,v,t;
int sigma;
double p;
int h,h1,h2;
int t0,t1,t2;
int main()
{
scanf("%d%d%d%d%d%d",&n,&m,&q,&u,&v,&t);
p=(double) u/v; int tmp;
for(t0=1; t0<=n; ++t0)
scanf("%d",&now[t0]);
t0--; t1=t2=0; h=h1=h2=1;
sort(now+1,now+t0+1,cmp);
int top;
for(int i=1; i<=m; i++)
{
if(h>t0)
{
if(cut1[h1]>cut2[h2]) top=cut1[h1++]; else top=cut2[h2++];
}
else if(now[h]>=cut1[h1]&&now[h]>=cut2[h2]) top=now[h],++h;
else if(cut1[h1]>=cut2[h2]&&now[h]<=cut1[h1]) top=cut1[h1],++h1;
else top=cut2[h2],++h2;
top+=sigma;
int a1=floor(p*(double) top) ,a2=top-a1;
sigma+=q;
a1-=sigma,a2-=sigma;
cut1[++t1]=a1,cut2[++t2]=a2;
if(i%t==0) printf("%d ",top);
}
printf("\n");
for(int i=h; i<=t0; i++) ans.push(now[i]);
for(int i=h1; i<=t1; i++) ans.push(cut1[i]);
for(int i=h2; i<=t2; i++) ans.push(cut2[i]);
for(int i=1; ans.size(); i++)
{
if(i%t==0) printf("%d ",()+sigma);
ans.pop();
}
return 0;
}