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)

  • 相关阅读:
    收集常用的.net开源项目
    前端兼容性
    IntelliJ IDEA 14 注册码生成器
    Web开发者的10个最好的云开发环境
    [置顶] 浅谈大型web系统架构
    简单的前端js+ajax 购物车框架(入门篇)
    CSS3 background-size图片自适应
    CSS clip:rect矩形剪裁功能及一些应用介绍
    Aspx 页面生命周期
    Asp.Net页面(母版页)加载顺序
  • 原文地址:https://www.cnblogs.com/rausen/p/4547430.html
Copyright © 2011-2022 走看看