zoukankan      html  css  js  c++  java
  • 2015 ACM-ICPC国际大学生程序设计竞赛北京赛区网络赛 1002 Mission Impossible 6

    题目链接:

      #1228 : Mission Impossible 6

    解题思路:

      认真读题,细心模拟,注意细节,就没有什么咯!写这个题解就是想记录一下rope的用法,以后忘记方便复习。

      rope(块状链表)属于SGI STL的一部分,不属于ISO C++标准库,但libstdc++-v3也包含了扩展,在头文件#include<ext/rope>,using namespace __gnu_cxx命名空间中。可以在很短的时间内实现快速的插入、删除和查找字符串。

    rope.size()              返回容器中元素个数

    rope.length()            返回容器中元素个数

    rope.begin()             返回一个头指针

    rope.end()              返回一个尾指针

    rope.empty()            返回容器是否为空

    rope.at(size_t i)            返回rope中第i个元素

    rope.pop_front()           弹出第一个元素

    rope.pop_back()           弹出最后一个元素

    rope.push_front()         在最前端插入一个元素

    rope.push_back()         在尾端插入一个元素

    rope.substr(size_t  i, size_t n)    提取以i开头长度为n的序列返回给rope

    rope.replace(size_t i, charT c)     i后面的元素都替换为c

    rope.erase(size_t i, size_t n)     删除从i开始,连续n个元素

    rope.insert(size_t i, charT c)     在i元素前面插入字符c

      1 #include <cstdio>
      2 #include <cstring>
      3 #include <iostream>
      4 #include <algorithm>
      5 #include <ext/rope>
      6 using namespace std;
      7 using namespace __gnu_cxx;
      8 /*
      9     鬼畜的模拟题!从新拿出来写一下还是会出错
     10     其实用rope写还是方便很多的
     11     注意一下题目的坑还是很容易过的
     12     1:每次复制文本为空,粘贴板才会清空
     13     2:当在复制状态为start时,操作D会使光标改变
     14     3:如果在文档限制长度内,不能把粘贴板上的内容复制完,则不操作
     15     4:除L,R外任何字符都能把复制状态从start转化为nothing
     16 */
     17 const int maxn = 20000;
     18 char b[maxn];
     19 int main ()
     20 {
     21     int T, n;
     22     int mark, c_state, t_state, len;
     23     scanf ("%d", &T);
     24     while (T --)
     25     {
     26         crope c, a;
     27         scanf ("%d %s", &n, b);
     28         len = strlen (b);
     29         t_state = 1;
     30         c_state = -2;
     31         mark = -1;
     32         for (int i=0; i<len; i++)
     33         {
     34             if (b[i]<='z' && b[i]>='a')
     35             {
     36                 if (c_state != -2)
     37                     c_state = -2;
     38                 if (t_state == 1 || a.size()==mark+1)
     39                 {
     40                     if (a.size() >= n)
     41                         continue;
     42                     a.insert(mark+1,b[i]);
     43                 }
     44                 else
     45                 {
     46                     a.erase (mark+1, 1);
     47                     a.insert (mark+1, b[i]);
     48 
     49                 }
     50                 mark ++;
     51             }
     52             else if (b[i] == 'L')
     53             {
     54                 if (mark > -1)
     55                     mark --;
     56             }
     57             else if (b[i] == 'R')
     58             {
     59                 if (a.size() > mark+1)
     60                     mark ++;
     61             }
     62             else if (b[i] == 'S')
     63             {
     64                 if (c_state != -2)
     65                     c_state = -2;
     66                 t_state = (t_state + 1) % 2;
     67             }
     68             else if (b[i] == 'D')
     69             {
     70                 if (c_state != -2)
     71                 {
     72                     if (mark > c_state)
     73                         a.erase (c_state + 1, mark - c_state);
     74                     if (c_state > mark)
     75                         a.erase (mark + 1, c_state - mark);
     76                     mark = min (mark, c_state);
     77                     c_state = -2;
     78                 }
     79                 else if (a.size() > mark+1)
     80                     a.erase( mark+1, 1);
     81             }
     82             else if (b[i] == 'B')
     83             {
     84                 if (c_state != -2)
     85                     c_state = -2;
     86                 if (mark > -1)
     87                     a.erase (mark, 1), mark --;
     88             }
     89             else if (b[i] == 'C')
     90             {
     91                 if (c_state == -2)
     92                     c_state = mark;
     93                 else
     94                 {
     95                     c = a.substr (min(c_state, mark)+1, max(c_state, mark)-min(c_state, mark));
     96                     c_state = -2;
     97                 }
     98             }
     99             else if (b[i] == 'V')
    100             {
    101                 if (c_state != -2)
    102                     c_state = -2;
    103                 int mm = a.size() + c.size();
    104                 if (t_state == 1 && mm > n)
    105                     continue ;
    106                 mm = mark + 1 + c.size();
    107                 if (t_state == 0 && mm > n)
    108                     continue ;
    109                 mm = c.size();
    110                 for (int j=0; j<mm; j++)
    111                 {
    112                     if (t_state == 1 || a.size()==mark+1)
    113                     {
    114                         if (a.size() >= n)
    115                             continue;
    116                         a.insert (mark+1, c.at(j));
    117                     }
    118                     else
    119                     {
    120                         a.erase (mark+1, 1);
    121                         a.insert (mark+1, c.at(j));
    122                     }
    123                     mark ++;
    124                 }
    125             }
    126         }
    127         if (a.size() == 0)
    128             printf ("NOTHING
    ");
    129         else
    130             cout<<a<<endl;
    131     }
    132     return 0;
    133 }
    134 /*
    135 3
    136 5 abaaaCLLLLCDLV
    137 5 abcdeSLLCLLLCRRV
    138 5 abcdeCLLLCSCRRRRDV
    139 
    140 aaaa
    141 ababc
    142 abcde
    143 */
    本文为博主原创文章,未经博主允许不得转载。
  • 相关阅读:
    listctrl中的cell如何支持被复制
    Can not issue data manipulation statements with executeQuery()的解决方案
    Jenkins工具学习(一)
    如何对图片进行测试
    WebDriver常用的api
    Cannot get a STRING value from a NUMERIC cell问题的解决办法
    Eclipse中安装springmvc插件
    Tomcat 的端口被占用的解决办法
    pyCharm最新激活码(2018激活码)
    Error: Error occured while starting App. Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
  • 原文地址:https://www.cnblogs.com/alihenaixiao/p/4898974.html
Copyright © 2011-2022 走看看