zoukankan      html  css  js  c++  java
  • 蚯蚓

    # 题意
    开始有n只蚯蚓,m次操作,每次选出最大的一条,切分成floor(x*u/v)和x-floor(x*u/v),分别作为新的加入集合,长度可以为0,一个参数t每当t次的时候就输出操作之前的数,
    所有操作操作完了以后,从大到小分别输出t的倍数。

    # 题解
    首先用一个偏移量记录所有数列增加的q的值,因为只有被操作的不加q所以被操作的两个数都减去q,然后开三个队列来分别记录原始序列,和两段切分完后的序列,
    显然每次操作完成后的两段分别都是各自队列中的最大值,因为操作的数都没有加q,所以显然正确。
    开始时将初始序列从大到下排序
    每次操作时只需要将三个中的最大值进行操作
    小注意:
    1)每次操作的时候都要加上偏移量进行操作,否则会出错
    2)加入之前先算出来两个数操作完的数,再减偏移量

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int N=1e5+10,M=7e6+10;
     4 int n,m,q,t,u,v;
     5 int all[N],h0,t0;
     6 int que1[M],h1,t1=-1;
     7 int que2[M],h2,t2=-1;
     8 int delta;
     9 bool cmp(int a,int b){
    10    return a>b;
    11 }
    12 int get(){
    13    int x=INT_MIN;
    14    if(h1<=t1) x=max(que1[h1],x);
    15    if(h2<=t2) x=max(que2[h2],x);
    16    if(h0<=t0) x=max(all[h0],x);
    17 
    18    if(h0<=t0 && x==all[h0]) h0++;
    19    else if(h1<=t1 && x==que1[h1]) h1++;
    20    else h2++;
    21    return x;
    22 }
    23 int main(){
    24    cin>>n>>m>>q>>u>>v>>t;
    25    for(int i=0;i<n;i++) {
    26       cin>>all[i];
    27    }
    28    sort(all,all+n,cmp);
    29    t0=n-1;
    30    for(int i=1;i<=m;i++){
    31       int now=get();
    32       now += delta;
    33       if(i % t == 0) cout<<now<<' ';
    34       int l = now * 1ll * u / v;
    35       int r = now - l;
    36       delta+=q;
    37       l-=delta;
    38       r-=delta;
    39       que1[++t1]=l;
    40       que2[++t2]=r;
    41    }
    42    cout<<endl;
    43    for(int i=1;i<=n+m;i++){
    44       int x=get();
    45       if(i%t==0)
    46          cout<<x+delta<<' ';
    47    }
    48 }
  • 相关阅读:
    C++进程通信之命名管道
    从Win32过渡到MFC工程
    Windows常用消息处理与自定义消息
    Windows窗口开发原理(窗口的创建&消息机制)
    _T、_TEXT、TEXT、L的使用记录
    几种多线程同步方式总结
    异步编程之async&await
    rpc理解
    docker 基础namespace cgroup overlayfs network
    python编程书籍资料整理大全
  • 原文地址:https://www.cnblogs.com/hhyx/p/12495718.html
Copyright © 2011-2022 走看看