【题解】洛谷P2827[NOIP2016]蚯蚓 优先队列+模拟

82 篇文章 0 订阅
35 篇文章 0 订阅

题目链接
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


最开始敲了个85的模拟……想想也没那么简单。
学习了大佬题解,其中单调性很关键。

#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#define re register 
using namespace std;
template<class T>inline void read(T&x)
{
	x=0;re int f=0;re char ch=getchar();
	while(ch<'0'||ch>'9')f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	if(f)x=-x;
}
template<class M>inline void write(M x)
{
	re int buf[40],p=0;
	if(x<0)putchar('-'),x=-x;
	do{
		buf[p++]=x%10;x/=10;
	}while(x);
	for(re int i=p-1;i>=0;i--)putchar(buf[i]+48);
	putchar(' ');
}
const int N=7e6+10;
int n,m,q,u,v,t,sigma,t0,t1,t2,h0,h1,h2,cut1[N],cut2[N],now[N];
double p;
priority_queue<int>ans;
inline bool cmp(const int &a,const int &b){return a>b;}
int main()
{
	//freopen("in.txt","r",stdin);
    read(n);read(m);read(q);read(u);read(v);read(t);
    p=(double)u/v;
    for(re int i=1;i<=n;i++)
        read(now[i]);
    t0=n;t1=t2=0;h0=h1=h2=1;
    sort(now+1,now+n+1,cmp);
    re int top;
    for(re int i=1,a1,a2;i<=m;i++)
    {
    	if(h0>t0)
    	{
    		
    		if(cut1[h1]>cut2[h2])top=cut1[h1++];
    		else top=cut2[h2++];
		}
		else if(now[h0]>=cut1[h1]&&now[h0]>=cut2[h2])top=now[h0++];
		else if(now[h0]<=cut1[h1]&&cut2[h2]<=cut1[h1])top=cut1[h1++];
		else top=cut2[h2++];
		top+=sigma;
		a1=floor(p*(double)top);a2=top-a1;
		a1-=sigma+q;a2-=sigma+q;
		cut1[++t1]=a1;cut2[++t2]=a2;
		if(i%t==0)write(top);sigma+=q;
	}
	putchar('\n');
	for(re int i=h0;i<=t0;i++)ans.push(now[i]);
	for(re int i=h1;i<=t1;i++)ans.push(cut1[i]);
	for(re int i=h2;i<=t2;i++)ans.push(cut2[i]);
	for(re int i=1;ans.size();i++)
	{
		if(i%t==0)write(ans.top()+sigma);
		ans.pop();
	}
	return 0;
}

总结

挺好的一个大模拟。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值