zoukankan      html  css  js  c++  java
  • 【伪·题解】高级打字机

      

    Problem 1 高级打字机(type.cpp/c/pas)

    【题目描述】

    早苗入手了最新的高级打字机。最新款自然有着与以往不同的功能,那就是它具备撤销功能,厉害吧。

    请为这种高级打字机设计一个程序,支持如下3种操作:

    1.T x:在文章末尾打下一个小写字母x。(type操作)

    2.U x:撤销最后的x次修改操作。(Undo操作)

    (注意Query操作并不算修改操作)

    3.Q x:询问当前文章中第x个字母并输出。(Query操作)

    文章一开始可以视为空串。

    【输入格式】

    第1行:一个整数n,表示操作数量。

    以下n行,每行一个命令。保证输入的命令合法。

    【输出格式】

    每行输出一个字母,表示Query操作的答案。

    【样例输入】

    7

    T a

    T b

    T c

    Q 2

    U 2

    T c

    Q 2

    【样例输出】

    b

    c

    【数据范围】

    对于40%的数据 n<=200;

    对于100%的数据 n<=100000;保证Undo操作不会撤销Undo操作。

    <高级挑战>

    对于200%的数据 n<=100000;Undo操作可以撤销Undo操作。

    <IOI挑战>

    必须使用在线算法完成该题。

    弱鸡只能过undo不能撤销undo的,据闻高级挑战正确解法是字典树然后搞树上倍增……

    下附模拟代码

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <fstream>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <string>
     7 #include <cmath>
     8 using namespace std;
     9 ifstream fin("type.in");
    10 ofstream fout("type.out");
    11 char xl[1000005];
    12 int zx=1;
    13 void add(char z);//tybe
    14 void cx(int hs);//undo
    15 int main(void)
    16 {
    17  char cz,zm;
    18  int gs=0,zls=0;
    19  fin>>zls;
    20  for(int i=1;i<=zls;i++)
    21  {
    22   if(zx<0)zx=0;
    23   fin>>cz;
    24   if(cz=='T')fin>>zm;
    25   else fin>>gs;
    26   if(cz=='T')add(zm);
    27   if(cz=='U')cx(gs);
    28   if(cz=='Q')fout<<xl[gs]<<"
    ";
    29   gs=0;
    30  }
    31  return 0;
    32 }
    33 
    34 void add(char z)
    35 {
    36  xl[zx]=z;
    37  zx++;
    38  return;
    39 }
    40 
    41 void cx(int hs)
    42 {
    43  zx-=hs;
    44  return;
    45 }
  • 相关阅读:
    Leetcode 126.单词接龙II
    Leetcode 125.验证回文串
    Leetcode 124.二叉树中的最大路径和
    Leetcode 123.买卖股票的最佳时机III
    Leetcode 122.买卖股票的最佳时机II
    西子凌波回复集5(网友整理版)
    西子凌波回复集4(网友整理版)
    西子凌波回复集3(网友整理版)
    K杀(逻辑-标准-规则)
    西子凌波49:2018年11月29日微博解盘提示
  • 原文地址:https://www.cnblogs.com/CYWer/p/4817061.html
Copyright © 2011-2022 走看看