zoukankan      html  css  js  c++  java
  • [LUOGU] P2827 蚯蚓

    优先队列模拟题意,有60分

    看了题解,蚯蚓切割后长度单调下降,可以用三个队列分别维护:未切割的蚯蚓,切割后长的蚯蚓,切割后短的蚯蚓。

    每次从三个队头取出最大的,进行切割即可。

    自己写了个残缺的queue,qwq

    #include<algorithm>
    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<cmath>
    #define int long long
    using namespace std;
    
    inline int rd(){
        int ret=0,f=1;char c;
        while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;
        while(isdigit(c))ret=ret*10+c-'0',c=getchar();
        return ret*f;
    }
    
    const int MAXN=10000005;
    
    int n,m,q,u,v,t;
    int T;
    int data[MAXN];
    struct Node{
        int len,tim;
        Node(int x=0,int y=0){len=x;tim=y;}
        long long calc(){return max(len+(T-tim)*q,0ll);}
    };
    
    struct Queue{
        Node val[MAXN];
        int front,tail;
        Queue(){front=1;tail=0;}
        void add(int x,int tim){val[++tail]=Node(x,tim);}
        int pop(){return front<=tail?val[front++].calc():-1;}
        int top(){return front<=tail?val[front].calc():-1;}
    }Q[3];
    
    long double pos;
    
    void gmax(int &id,int &val){
        int ret=0;
        if(Q[0].top()<Q[1].top()) ret=1;else ret=0;
        if(Q[ret].top()<Q[2].top()) ret=2;
        id=ret;val=Q[id].top();
    }
    
    signed main(){
        n=rd();m=rd();q=rd();
        u=rd();v=rd();t=rd();
        pos=1.0*u/v;
        int x,y;
        
        for(int i=1;i<=n;i++) {
            data[i]=-rd();
        }
        sort(data+1,data+1+n);
        for(int i=1;i<=n;i++) Q[0].add(-data[i],1);
        for(T=1;T<=m;T++){
            gmax(x,y);
            Q[1].add(floor(y*pos),T+1);
            Q[2].add(y-floor(y*pos),T+1);
            Q[x].pop();
            if(!(T%t)) printf("%lld ",y);
        }
        puts("");
        for(int i=1;i<=m+n;i++){
            gmax(x,y);
            Q[x].pop();
            if(!(i%t)) printf("%lld ",y);
        }
        return 0;
    }

    本文来自博客园,作者:GhostCai,转载请注明原文链接:https://www.cnblogs.com/ghostcai/p/9370859.html

  • 相关阅读:
    Retrofit2源码分析
    Android8.0硬件加速的重绘流程
    Android单元测试
    rand5->rand7,rand7->rand10
    快速排序的随机化版本
    快速排序
    亦或实现交换
    在最坏情况下,找到n个元素中第二小的元素需要n+lgn-2次比较
    3*n/2时间内求出最大最小值
    基数排序
  • 原文地址:https://www.cnblogs.com/ghostcai/p/9370859.html
Copyright © 2011-2022 走看看