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\n");
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 */
时间: 2024-12-25 07:05:59

2015 ACM-ICPC国际大学生程序设计竞赛北京赛区网络赛 1002 Mission Impossible 6的相关文章

ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络练习赛 题目4 : Beautiful String

We say a string is beautiful if it has the equal amount of 3 or more continuous letters (in increasing order.) Here are some example of valid beautiful strings: "abc", "cde", "aabbcc", "aaabbbccc". Here are some exa

ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6

#1228 : Mission Impossible 6 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You must have seen the very famous movie series,"Mission Impossible", from 1 to 4. And "Mission Impossible 5" is now on screen in China. Tom Cruise is just learning pro

ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛

#1235 : New Teaching Buildings 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 Thanks to the generous finance income, Programming Monkey Elementary School is going to build three new teaching buildings. The school could be seen as a connected graph with n vert

ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 The Book List

描述 The history of Peking University Library is as long as the history of Peking University. It was build in 1898. At the end of year 2015, it had about 11,000 thousand volumes of books, among which 8,000 thousand volumes were paper books and the othe

hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n days and the date of these days can be represented by n integers: 0, 1, 2, -, n-1. He plans to spend m consecutive days(2 ≤ m ≤ n)in Beijing. Durin

hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

#1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, country A and country B. They are in a war, and keep launching missiles towards each other. It is known that country A will launch N missiles. The i-th miss

hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

#1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people could not tolerate the pollution in the city any more, and started a long-lasting protest. Eventually, the municipal government made up its mind to deal w

hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess games. There are many famous War Chess games such as "Biography of Cao Cao", "Anecdotes of Wagang Mountain", etc. In this problem, let's c

ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛

题目1 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n days and the date of these days can be represented by n integers: 0, 1, 2, -, n-1. He plans to spend m consecutive days(2 ≤ m ≤ n)in Beijing. During