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)

  • 相关阅读:
    【洛谷P1330】封锁阳光大学
    【洛谷P1087】FBI树
    hdu 4504(动态规划)
    hdu 4503(数学,概率)
    hdu 5400(思路题)
    hdu 5701(区间查询思路题)
    hdu 4502(DP)
    hdu 1401(单广各种卡的搜索题||双广秒速)
    hdu 1258(DFS)
    hdu 1254(搜索题)
  • 原文地址:https://www.cnblogs.com/rausen/p/4547430.html
Copyright © 2011-2022 走看看