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

    ★★   输入文件:earthworm.in   输出文件:earthworm.out   简单对比
    时间限制:1 s   内存限制:512 MB

    【题目描述】

    【输入格式】

       从文件earthworm.in中读入数据。

       第一行包含六个整数n,m,q,u,v,t

       其中n,m,q的意义见【问题描述】

       u,v,t均为正整数;

        你需要自己计算p = u/v(保证。<u<v>;  t是输出参数,其含义将会在【输出格式】中解释。

       第二行包含n个非负整数,为al,a2,...,an,即初始时n只蚯蚓的长度。

       同一行中相邻的两个数之间,恰好用一个空格隔开。

       保证1<n<105,0<m<7*10^6,0<u<v< 10^9,0<q<200,1<t<71,0<a_i<10^8

    【输出格式】

     

    【样例1输入】

    3 7 1 1 3 1
    3 3 2

    【样例1输出】

    3 4 4 4 5 5 6
    6 6 6 5 5 4 4 3 2 2

    【提示】

       在神刀手到来前:3只蚯蚓的长度为3,3,2。

       1秒后:一只长度为3的蚯蚓被切成了两只长度分别为1和2的蚯蚓,其余蚯蚓的长度增加了1。最终4只蚯蚓的长度分别为((1,2),4,3。括号表示这个位置刚刚有一只蚯蚓被切断。

       2秒后:一只长度为4的蚯蚓被切成了1和3 0  _5只蚯蚓的长度分别为:2,3,(1,3),4。

       3秒后:一只长度为4的蚯蚓被切断。6只蚯蚓的长度分别为:3,4,2,4,(1,3)。

       4秒后:一只长度为4的蚯蚓被切断。7只蚯蚓的长度分别为:4,(1,3),3,5,2,4。

       5秒后:一只长度为_5的蛆叫被切断。8只蚯蚓的长度分别为:5,2,4,4,(1,4),3,5。

       6秒后:一只长度为_5的蚯蚓被切断。9只蚯蚓的长度分别为:(1,4),3,5,5,2,5,4,6。

       7秒后:一只长度为6的蚯蚓被切断。10只蚯蚓的长度分别为:2,5,4,6,6,3,6,5,(2,4)。

       所以,7秒内被切断的蚯蚓的长度依次为3,4,4,4,5,5,60  7秒后,所有蚯蚓长度从大到小排序为6,6,6,5,5,4,4,3,2,2。

    【样例2输入】

    3 7 1 1 3 2
    3 3 2

    【样例2输出】

    4 4 5
    6 5 4 3 2
    

    【提示2】

    这个数据中只有t=2与上个数据不同。只需在每行都改为每两个数输出一个数即可 虽然第一行最后有一个6没有被输出,但是第二行仍然要重新从第二个数再开始输出

    【样例3输入】

    3 7 1 1 3 9
    3 3 2
    

    【样例3输出】

    2
    

    【提示3】

    这个数据中只有t=9与上个数据不同。 注意第一行没有数要输出,但也要输出一个空行。

    【来源】

    NOIP2016 官方数据

    思路:三队列模拟;

    q1存初始蚯蚓,q2存新生蚯蚓A,q3存新生蚯蚓B,q1队列只取不放;(这里可以证明q2,q3是单调的)

    模拟n次切割;

    最后合并的q4中;(不要先放入,再sort,直接按序放入,不然和我一样Tcg)

    代码实现:

     1 #include<cstdio>
     2 #include<algorithm>
     3 using namespace std;
     4 const int maxn=1e5+10;
     5 const int maxm=1e7+10;
     6 int n,m,q,u,v,t;
     7 int a,b,c;
     8 int t1,h2,t2,h3,t3,h4;
     9 int q1[maxn],q2[maxm],q3[maxm],q4[maxn+maxm];
    10 inline bool cmp(int x,int y){return x>y;}
    11 int get(int k){
    12     int x=q1[t1]+q*k,y=q2[t2]+q*(k-t2-1),z=q3[t3]+q*(k-t3-1);
    13     if(n>t1&&x>=y&&x>=z){t1++;return x;}
    14     else if(h2>t2&&y>=z){t2++;return y;}
    15     else if(h3>t3){t3++;return z;}
    16     else return -1;
    17 }
    18 int main(){
    19     freopen("earthworm.in","r",stdin);
    20     freopen("earthworm.out","w",stdout);
    21     scanf("%d%d%d%d%d%d",&n,&m,&q,&u,&v,&t);
    22     for(int i=0;i<n;i++) scanf("%d",&q1[i]);
    23     sort(q1,q1+n,cmp);
    24     for(int i=0;i<m;i++){
    25         a=get(i);
    26         if((i+1)%t==0) printf("%d ",a);
    27         b=1ll*a*u/v,c=a-b;
    28         q2[h2++]=b,q3[h3++]=c;
    29     }
    30     while(q4[h4]=get(m),q4[h4]!=-1) h4++;
    31     putchar('
    ');
    32     for(int i=t-1;i<h4;i+=t) printf("%d ",q4[i]);
    33     putchar('
    ');
    34     return 0;
    35 }

    题目来源:COGS,UOJ,洛谷

  • 相关阅读:
    基于策略梯度的强化学习论文调研
    Soft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic Actor
    固定随机种子比较强化学习算法
    Action and learning shape the activity of neuronal circuits in the visual cortex
    大脑中的记忆机制
    A Simple Neural Attentive Meta-Learner
    【Error】Creating Server TCP listening socket *:6379: bind: No such file or directory
    Redis安装配置
    MySQL中文入库问题
    Nginx启动/重启失败
  • 原文地址:https://www.cnblogs.com/J-william/p/6676406.html
Copyright © 2011-2022 走看看