POJ 2887 Big String
Time Limit: 1000MS | Memory Limit: 131072K | |
Total Submissions: 7053 | Accepted: 1684 |
Description
Input
The second line contains the number of manipulation commands N (0 < N ≤ 2,000). The following N lines describe a command each. The commands are in one of the two formats below:
- I ch p: Insert a character ch before the p-th character of the current string. If p is larger than the length of the string, the character is appended to the end of the string.
- Q p: Query the p-th character of the current string. The input ensures that the p-th character exists.
All characters in the input are digits or lowercase letters of the English alphabet.
Output
Sample Input
ab 7 Q 1 I c 2 I d 4 I e 2 Q 5 I f 1 Q 3
Sample Output
a d e
Source
题目大意
给一个字符串,长度不超过 106,有两种操作:
1、Q x(0 < x <= len(s)) 表示查询当前串中第x个字符
2、I c x(c为字母 0 < x <= len(s)+1)表示在第x个位置插入c字符 x == len+1表示在串尾插入
操作的总数不超过 2000
做法分析
块状链表裸题。详见代码
#include<cstdio> #include<cstring> #include<iostream> #define m(s) memset(s,0,sizeof s) using namespace std; const int N=1010; int l[N],n,m; char s[N*N],eg[N][N*3]; void insert(int x,char c){int n1=0,p1,pn=n;for(int i=1;i<=n;i++){if(n1+l[i]>=x){pn=i;break;}if(i==n) break;n1+=l[i];}p1=x-n1;l[pn]=max(p1,l[pn]+1);for(int i=l[pn];i>p1;i--) eg[pn][i]=eg[pn][i-1];eg[pn][p1]=c; } void query(int x){int n1=0,p1,pn=n;for(int i=1;i<=n;i++){if(n1+l[i]>=x){pn=i;break;}n1+=l[i];}p1=x-n1;printf("%c\n",eg[pn][p1]); } void work(){scanf("%d",&m);int len=strlen(s),ave;ave=(len+999)/1000;n=(len-1)/ave+1;for(int i=0;i<len;i++) eg[i/ave+1][i%ave+1]=s[i],l[i/ave+1]++;while(m--){char c[2];int x;scanf("%s",c);if(c[0]=='I') scanf("%s%d",c,&x),insert(x,c[0]);else scanf("%d",&x),query(x);} } int main(){while(scanf("%s",s)==1){m(l);m(eg);work();} return 0; }
转载于:https://www.cnblogs.com/shenben/p/6270672.html
POJ 2887 Big String相关推荐
- oracle rman备份时间点,Oracle Rman 控制RMAN的备份时间,减少IO消耗
一.问题描述 由于服务器配置不高,备份策略为周末全备.周一至周六差异备份. 平时服务器CPU使用30%左右. 全备份时,开启两个通道,CPU达到70%-80%左右,业务不卡顿.不掉单,session不 ...
- Poj 2887-Big String Splay
题目:http://poj.org/problem?id=2887 Big String Time Limit: 1000MS Memory Limit: 131072K Total Submis ...
- POJ 1002 487-3279
2019独角兽企业重金招聘Python工程师标准>>> 487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissi ...
- 字符串匹配のKMP【专题@AbandonZHANG】
算法详解 很长时间内都没有能够很理解KMP算法的精髓,尤其是很多书上包括<算法导论>没有把next函数(亦或 π函数)讲解的很透彻. 今天去看了matrix67大牛博客中关于kmp部分的讲 ...
- 字符串匹配のKMP【@Abandon】
算法详解 很长时间内都没有能够很理解KMP算法的精髓,尤其是很多书上包括<算法导论>没有把next函数(亦或 π函数)讲解的很透彻. 今天去看了matrix67大牛博客中关于kmp部分的讲 ...
- Java知识——精华总结
Java知识--精华总结 一.java概述与基础知识 1.何为编程? 编程就是让计算机为解决某个问题而使用某种程序设计语言编写程序代码,并最终得到结果的过程. 为了使计算机能够理解人的意图,人类就必须 ...
- 【贪心】Sunscreen(poj 3614/luogu 2887)
Sunscreen poj 3614 luogu 2887 题目大意: 有n个人,每个人要求选一个价值在minniminn_iminni到maxximaxx_imaxxi的物品,现在有m件物品,每 ...
- POJ 3268 D-Silver Cow Party
http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...
- POJ 2226 Muddy Fields 最小点覆盖+加建图(好题)
题目链接 题目一看就是最小点覆盖,这道题与POJ - 3041 算是一类题,但是3041算是一道十分裸的,因为删除的是整行或者整列,所以图其实是现成的,但是本题的难点就在如何建图. 思路:首先还是尽量 ...
最新文章
- 【Java】剑指 Offer 52. 两个链表的第一个公共节点
- Linux日志系统-07:案例3-rsyslog+logrotate实现SSH的日志滚动
- thinkphp html php文件,ThinkPHP生成静态HTML文件
- NodeJs实现下载Excel文件
- Spring精华问答 | Spring Boot有哪些优点?
- 网页统计所用到的名词解析
- ES6-使用let关键字定义变量
- Poj 2001 Shortest Prefix(字典树模板)
- vs C4996的错误解决方法
- c语言中宏名的作用时段,C语言中的宏定义!
- 爬取西刺代理的免费IP
- 前后端分离前端框架的主要内容是什么?
- 画地貌图matlab
- DP/最短路 URAL 1741 Communication Fiend
- mysql插入成功返回主键_MyBatis + MySQL返回插入成功后的主键id
- Java 多态的薪酬计算的练习
- js设计模式——组合模式
- 问题分析工具 - 3 legged 5 why analysis
- IntelliJ IDEA 安装和使用
- DockerFile---构建docker镜像的文件