POJ2887 Big String 块状链表
来源:互联网 发布:大鱼端口查看器下载 编辑:程序博客网 时间:2024/04/28 10:37
块状链表初体验 ╮(╯▽╰)╭~~
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define mxn 1000020#define N 1000#define N2 2003char s[mxn];struct node {char a[N2];int cnt;node() {cnt = 0;nxt = pre = NULL;}node *nxt, *pre;void split() {if( cnt < N2 - 3 )return ;node* tmp = new node;for( int i = cnt / 2 + 1; i <= cnt; ++i )tmp -> a[++tmp->cnt] = a[i];cnt /= 2;tmp -> pre = this;tmp -> nxt = nxt;nxt = tmp;}void insert( int k, char c ) {if( k > cnt ) {if( nxt == NULL ) {a[++cnt] = c;split();}else {nxt -> insert( k - cnt, c );}return ;}for( int i = cnt + 1; i > k + 1; --i )a[i] = a[i-1];a[k+1] = c;cnt++;split();}char get_k( int k ) {if( k > cnt )return nxt -> get_k( k - cnt );return a[k];}}*head;int main() {//freopen( "tt.txt", "r", stdin );while( scanf( "%s", s + 1 ) != EOF ) {head = new node;node* now = head;int tot = 0;for( int i = 1; s[i]; ++i ) {now -> a[++now->cnt] = s[i];if( i > tot + N ) {now -> nxt = new node;now -> nxt -> pre = now;now = now -> nxt;tot += N;}}int m;scanf( "%d", &m );while( m-- ) {char str[3];scanf( "%s", str );if( str[0] == 'Q' ) {int k;scanf( "%d", &k );printf( "%c\n", head -> get_k( k ) );continue;}int k;scanf( "%s %d", str, &k );k--;head -> insert( k, str[0] );}}return 0;}
0 0
- POJ2887 Big String 块状链表
- 【POJ2887】【块状链表】Big String
- Big String-POJ2887块状数组
- 块状链表 poj2887
- POJ2887【块状链表】
- [POJ 2887] Big String [块状链表]
- 【POJ 2887】Big String 块状链表
- POJ 2887Big String(块状链表)
- poj 2887 Big String 块状链表
- POJ 2887 Big String 块状链表
- poj 2887 big string (块状链表)
- [POJ2887]Big String 做题笔记
- POJ2887 块状数组
- 【POJ 2887】Big String(块状数组)
- Poj 2887 Big String(块状数组)
- poj2887
- POJ2887
- 块状链表
- 奔驰扬声器
- 程序员生存定律[八] 借势的价值和力量
- 奈公开赛音频工程学校
- 【Visual C++】游戏开发笔记十七 游戏基础算法(一) 游戏随机系统初步
- C++大数模版(转载)
- POJ2887 Big String 块状链表
- 1407251735-hd-美素数.cpp
- HDU 2031 进制转换
- 【Visual C++】游戏开发笔记十八 游戏基础物理建模(一) 匀速与加速运动
- cocos2dx 2.2.3编译第一个apk到安卓手机
- 电脑快捷键
- 仓厦缚源竟纠芯粕窖吻柯餐
- 坊艺薪泻挠刎实赣募柑油粮
- 乌酥却俸瀑旱苹吠懈蛊邑胺