NOIP2016 T5 蚯蚓

解题报告

如果光用优先队列会超时。
可以发现如果先排序,那每条蚯蚓按比例切开后的[px]和x-[px]仍分别单调递减,所以可以开3个队列分别放原始长度,[px]部分和x-[px]部分,每次取三个队首中最长的即可。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int getint()
{
    int i=0,f=1;char c;
    for(c=getchar();(c>'9'||c<'0')&&c!='-';c=getchar());
    if(c=='-')f=-1,c=getchar();
    for(;c>='0'&&c<='9';c=getchar())i=(i<<1)+(i<<3)+c-'0';
    return i*f;
}

const int N=8e6+5,INF=0x3f3f3f3f;
int n,m,q,u,v,t,h1,h2,h3,t1,t2,t3,delta;
int q1[N],q2[N],q3[N];
double p;

bool cmp(const int &a,const int &b)
{
    return a>b;
}

int getmax()
{
    int a=-INF,b=-INF,c=-INF,x;
    if(h1<t1)a=q1[h1+1]+delta;
    if(h2<t2)b=q2[h2+1]+delta;
    if(h3<t3)c=q3[h3+1]+delta;
    x=max(a,max(b,c));
    if(x==a)h1++;
    else if(x==b)h2++;
    else h3++;
    return x;
}

int main()
{
    //freopen("lx.in","r",stdin);
    n=getint(),m=getint(),q=getint(),u=getint(),v=getint(),t=getint();
    p=u*1.0/v;
    for(int i=1;i<=n;i++)q1[++t1]=getint();

    sort(q1+1,q1+t1+1,cmp);

    for(int i=1;i<=m;i++)
    {
        int x=getmax();
        int tmp=(long long)x*u/v;
        delta+=q;
        q2[++t2]=tmp-delta;
        q3[++t3]=x-tmp-delta;
        if(i%t==0)cout<<x<<" ";
    }
    cout<<'\n';

    for(int i=1;i<=n+m;i++)
    {
        int x=getmax();
        if(i%t==0)cout<<x<<" ";
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值