zoukankan      html  css  js  c++  java
  • BZOJ2408 混乱的置换

    这道题即THUSC 2015 t3...只不过数据范围$n, m ≤ 10^5$

    可以上网查这个鬼畜的东西"Burrows-Wheeler Transform"

    这道题要用到解压缩也就是IBWT算法,复杂度$O(n + m)$

     1 /**************************************************************
     2     Problem: 2408
     3     User: rausen
     4     Language: C++
     5     Result: Accepted
     6     Time:24 ms
     7     Memory:884 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11  
    12 using namespace std;
    13 const int N = 1e4 + 5;
    14  
    15 int getint();
    16  
    17 int n, m, st;
    18 int a[N], next[N], cnt[15];
    19  
    20 int main() {
    21     int i, j;
    22     n = getint(), m = getint();
    23     for (i = 1; i <= n; ++i) ++cnt[(a[i] = getint()) + 1];
    24     for (i = 1; i <= m; ++i) cnt[i] += cnt[i - 1];
    25     for (i = 1; i <= n; ++i) next[++cnt[a[i]]] = i;
    26     for (i = st = 1; i <= n; ++i) if (a[i] < a[st]) st = i;
    27     for (i = 1, j = st; i <= n; ++i) printf("%d%c", a[j], i == n ? '
    ' : ' '), j = next[j];
    28     return 0;
    29 }
    30  
    31 const int BUF_SIZE = 30;
    32 char buf[BUF_SIZE], *buf_s = buf, *buf_t = buf + 1;
    33 #define isdigit(x) ('0' <= x && x <= '9')
    34 #define PTR_NEXT() { 
    35     if (++buf_s == buf_t) 
    36         buf_s = buf, buf_t = buf + fread(buf, 1, BUF_SIZE, stdin); 
    37 }
    38  
    39 inline int getint() {
    40     register int x = 0;
    41     while (!isdigit(*buf_s)) PTR_NEXT();
    42     while (isdigit(*buf_s)) {
    43         x = x * 10 + *buf_s - '0';
    44         PTR_NEXT();
    45     }
    46     return x;
    47 }
    View Code

    (p.s. 窝考试的时候sb。。。只想出来了$O(mn)$的算法QAQAQQQ)

  • 相关阅读:
    JS 一键复制功能实现
    移动端点击弹窗后禁止页面滑动
    ui库地址总结
    react源码解析20.总结&第一章的面试题解答
    react源码解析19.手写迷你版react
    react源码解析18事件系统
    react源码解析17.context
    react源码解析16.concurrent模式
    react源码解析15.scheduler&Lane
    react源码解析14.手写hooks
  • 原文地址:https://www.cnblogs.com/rausen/p/4547430.html
Copyright © 2011-2022 走看看