zoukankan      html  css  js  c++  java
  • uva11922(强行用rope替代spaly)

    spaly没学过,用rope水过,

    rope是extension库中的东西,codeblocks编译器支持,

    需要包含

    #include <ext/rope>
    using namespace __gnu_cxx;

    rope的各种操作时间都是log(n)

    但是不提供翻转的操作,那么如何实现翻转呢?

    只要维护一正一反两个rope,

    正rope进行翻转更新的时候用到反rope

    反rope进行翻转更新的时候用到正rope

    代码非常之短。。。。

     1 #include <iostream>
     2 #include <string.h>
     3 #include <stdio.h>
     4 #include <time.h>
     5 #include <algorithm>
     6 #include <map>
     7 #include <ext/rope>
     8 using namespace __gnu_cxx;
     9 using namespace std;
    10 rope<int> ro;
    11 rope<int> revro;
    12 int main()
    13 {
    14     int n,m;
    15     scanf("%d%d",&n,&m);
    16     for(int i=1;i<=n;++i)
    17     {
    18         ro.append(i);
    19 
    20     }
    21     for(int i=n;i>=1;--i)
    22     {
    23         revro.append(i);
    24     }
    25     int l,r;
    26     while(m--)
    27     {
    28         scanf("%d%d",&l,&r);
    29         l--,r--;
    30         rope<int> tmp = ro.substr(l,r-l+1);
    31         rope<int> revtmp = revro.substr(n-r-1,r-l+1);
    32         ro.erase(l,r-l+1);
    33         revro.erase(n-r-1,r-l+1);
    34         ro.append(revtmp);
    35         revro = tmp + revro;
    36     }
    37     for(int i=0;i<n;++i)
    38         printf("%d
    ",ro[i]);
    39 
    40 }
  • 相关阅读:
    nodejs windows下安装运行
    第一篇博客
    vc 动态链接库编程2
    vc 动态链接库编程
    原生js实现图片在线预览
    玩转 css3
    CSS Hack整理
    PHP stdClass Object转array
    aptana studio3 汉化方法
    玩转 css3 续
  • 原文地址:https://www.cnblogs.com/justPassBy/p/4869787.html
Copyright © 2011-2022 走看看