P4241【NOIP2016 DAY2】蚯蚓

http://oi.nks.edu.cn/zh/Problem/Details?id=4241

题解

堆暴力60分

设当前时间两蚯蚓长度x,y且满足x>y,
所以 2秒后 x新长度为x*p+q
y新长度为(y+q)*p=y*p+q*p
因为q<0
又所以其新增的蚯蚓长度满足单调递增

所以考虑用三个单调队列来维护

代码

#include<stdio.h>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
#define maxn1  100005
#define maxn2  7200000
#define int long long
int n,m,q,u,v,t;
int a[maxn1];
struct node{
    int x,t;
};
bool cmp(int x,int y){
    return x>y;
}
deque<node>b;
deque<node>c;
int p1,q1;
int st=1;
void work(int x,int now)
{
    node t1,t2;
    if(now%t==0){
        printf("%d ",x);
    }
    p1=x*u/v;
    q1=x-p1;
    t1.x=p1;t1.t=now;
    t2.x=q1;t2.t=now;
    b.push_back(t1);
    c.push_back(t2);
}
main()
{
    int i,j,k;
    scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&q,&u,&v,&t);
    for(i=1;i<=n;i++) scanf("%lld",&a[i]);
    sort(a+1,a+1+n,cmp);
    if(m!=0) work(a[st++],1);
    for(i=2;i<=m;i++){
        int af=-1,bf=-1,cf=-1;
         if(st<=n) af=a[st]+(i-1)*q;
         if(b.size()) bf=b.front().x+(i-b.front().t-1)*q;
         if(c.size()) cf=c.front().x+(i-c.front().t-1)*q;
         if(af>=bf&&af>=cf){
           st++;
           work(af,i);  
         }
         else if(bf>=af&&bf>=cf){
            b.pop_front();
            work(bf,i);
         }
         else if(cf>=af&&cf>=bf){
            c.pop_front();
            work(cf,i);
         }
    }
    printf("\n");
    for(i=1;i<=m+n;i++){
        int maxx=0;
        int af=-1,bf=-1,cf=-1;
        if(st<=n) af=a[st]+m*q;
        if(!b.empty()) bf=b.front().x+(m-b.front().t)*q;
        if(!c.empty()) cf=c.front().x+(m-c.front().t)*q;
         if(af>=bf&&af>=cf){
           st++;
           maxx=af; 
         }
         else if(bf>=af&&bf>=cf){
            b.pop_front();
            maxx=bf;
         }
         else if(cf>=af&&cf>=bf){
            c.pop_front();
            maxx=cf;
         }
         if(i%t==0) printf("%lld ",maxx);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值