BZOJ2408 混乱的置换
这道题即THUSC 2015 t3...只不过数据范围$n, m ≤ 10^5$
可以上网查这个鬼畜的东西"Burrows-Wheeler Transform"
这道题要用到解压缩也就是IBWT算法,复杂度$O(n + m)$
/**************************************************************
Problem: 2408
User: rausen
Language: C++
Result: Accepted
Time:24 ms
Memory:884 kb
****************************************************************/ #include <cstdio> using namespace std;
const int N = 1e4 + ; int getint(); int n, m, st;
int a[N], next[N], cnt[]; int main() {
int i, j;
n = getint(), m = getint();
for (i = ; i <= n; ++i) ++cnt[(a[i] = getint()) + ];
for (i = ; i <= m; ++i) cnt[i] += cnt[i - ];
for (i = ; i <= n; ++i) next[++cnt[a[i]]] = i;
for (i = st = ; i <= n; ++i) if (a[i] < a[st]) st = i;
for (i = , j = st; i <= n; ++i) printf("%d%c", a[j], i == n ? '\n' : ' '), j = next[j];
return ;
} const int BUF_SIZE = ;
char buf[BUF_SIZE], *buf_s = buf, *buf_t = buf + ;
#define isdigit(x) ('0' <= x && x <= '9')
#define PTR_NEXT() { \
if (++buf_s == buf_t) \
buf_s = buf, buf_t = buf + fread(buf, , BUF_SIZE, stdin); \
} inline int getint() {
register int x = ;
while (!isdigit(*buf_s)) PTR_NEXT();
while (isdigit(*buf_s)) {
x = x * + *buf_s - '';
PTR_NEXT();
}
return x;
}
(p.s. 窝考试的时候sb。。。只想出来了$O(mn)$的算法QAQAQQQ)
BZOJ2408 混乱的置换的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 【做题】agc016d - XOR Replace——序列置换&环
原文链接 https://www.cnblogs.com/cly-none/p/9813163.html 题意:给出初始序列\(a\)和目标序列\(b\),都有\(n\)个元素.每次操作可以把\(a\ ...
- [LeetCode] LFU Cache 最近最不常用页面置换缓存器
Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the f ...
- [LeetCode] Longest Repeating Character Replacement 最长重复字符置换
Given a string that consists of only uppercase English letters, you can replace any letter in the st ...
- 页置换算法FIFO、LRU、OPT
页置换算法FIFO.LRU.OPT 为什么需要页置换 在地址映射过程中,若在页面中发现所要访问的页面不再内存中,则产生缺页中断.当发生缺页中断时操作系统必须在内存选择一个页面将其移出内存,以便为即将调 ...
- 【bzoj1231】[Usaco2008 Nov]mixup2 混乱的奶牛
题目描述 混乱的奶牛[Don Piele, 2007]Farmer John的N(4 <= N <= 16)头奶牛中的每一头都有一个唯一的编号S_i (1 <= S_i <= ...
- NOIP提高模拟题 混乱的队伍
混乱的奶牛 Description 混乱的奶牛 [Don Piele, 2007] Farmer John的N(4 <= N <= 16)头奶牛中的每一头都有一个唯一的编号S_i (1 & ...
- POJ2369 Permutations(置换的周期)
链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- POJ1026 Cipher(置换的幂运算)
链接:http://poj.org/problem?id=1026 Cipher Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
随机推荐
- AES 与Base64加密
public class AESHelper { /// <summary> /// 获取密钥 /// </summary&g ...
- windows平台下基于VisualStudio的Clang安装和配置
LLVM 是一个开源的编译器架构,它已经被成功应用到多个应用领域.Clang是 LLVM 的一个编译器前端,它目前支持 C, C++, Objective-C 以及 Objective-C++ 等编程 ...
- 我的Android第三章
先看效果图. 点击之后出变成 按钮内容改变了,并且弹出一个小提示 下面我们就来看看如何实现这个小案例 1)先打开string.xml文件,把要定义的字符串资源放置在里面 2)然后我们要画页面,基本An ...
- 外国javascript资源搜索
https://www.javascripting.com/search?q=canvas
- disable_irq与disable_irq_nosync使用场景
disable_irq与disable_irq_nosync使用场景 Linux设备驱动,关于中断屏蔽有两个接口:disable_irq和disable_irq_nosync,该两接口使用场景 ...
- QT笔记之VS2012 TCP传送文件
注意:工程监理后,因为用到网路,所以要加入对应的库 服务器: .h #ifndef TCPFILE_H #define TCPFILE_H #include <QtWidgets/QWidget ...
- C#自定义大小与改变大下的方法
在用VS的窗体设计器时,我们可以发现控件都是可以拖动的,并且还可以调整大小.怎么在自己的程序中可以使用上述功能呢? 下面的方法值得借鉴! using System; using System.Wind ...
- [转]SpringMVC拦截器简单教程
亲测有用,地址: http://blog.csdn.net/tjcyjd/article/details/7498236
- 泛型数组列表 ArrayList
为什么使用泛型数组列表而不使用普通数组? 1.普通数组经常会发生容量太大以致浪费的情况 2.普通数组无法动态更改数组 基本概念: 1.采用[类型参数]的[类]---->[泛型类] 2.[泛型类型 ...
- spring-task
cronExpression的配置说明,具体使用以及参数请百度google 字段 允许值 允许的特殊字符 秒 0-59 , - * / 分 0-59 , - * / 小 ...