蚯蚓

题目

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 ",ans.top()+sigma); 
		ans.pop(); 
	}
	return 0; 
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值