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

时间:2021-08-26 00:46:39

#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 programming through my MOOC course, and he wants a good score. So I made him divulge the story of "Mission Impossible 6".

In "Mission Impossible 6",  Ethan Hunt risks his life to install a mini camera in Bad Boss's room, in order to peep at the work Bad Boss does on his computer. Unfortunately, Bad Boss moves his desk to get more sunshine, and after that Ethan can't see the computer screen through the camera. Fortunately, Ethan can still see the keyboard. So, Ethan wants to know what Bad Boss writes on his computer by watching Bad Boss's keyboard inputs. That job is neither exciting nor risky, so it's really impossible for Ethan to accomplish --- that's why Tom Cruise wants to learn programming.

To simplified the problem, we assume that Bad Boss is editing a one line document, and the document consists of only lowercase letters. At first, there are nothing in the text editor window except a caret blinking at the left-most position (the starting position of the line). When Bad Boss input a lowercase letter, the letter appears at the right side of the caret, and then the caret moves to the right side of the letter just inputted. The text editor can switch between "insert mode" and "overwrite mode". When it's in "overwrite mode", the newly inputted letter will overwrite the letter which is on the right of the caret(if there is one). If it's in "insert mode", the newly inputted letter will be inserted before the letter which is originally on the right of the caret.

Besides inputting lowercase letters, Bad Boss can do some operations by inputting some uppercase letters, as described below:

'L' :  Moves the caret toward left by one letter. If the caret is already at the start of the line, then nothing happens.

'R':  Moves the caret toward right by one letter. If the caret is already at the end of the line(it means that there are no letters on the right side of the caret), then nothing happens.

'S':  Switch between "overwrite mode" and "insert mode". At the beginning, it's in "insert mode".

'D':  Delete a letter which is on the right of the caret. If the caret is already at the end of the line, then nothing happens. 'D' also has other effect which is described in 'C' operation below.

'B':  Delete a letter which is on the left of the caret. If the caret is already at the start of the line, then nothing happens.

'C': Copy something to the clipboard. At first , there is nothing in the clipboard, and the "copy status" of the editor is set to "NOTHING". When key 'C' is pressed:

If copy status is "NOTHING", copy status will be changed into "START", and the current position of caret is saved as "copy position 1".

if copy status is "START ", copy status will be changed into "NOTHING" and the letters between current caret position and the saved "copy position 1" will be copied into clipboard(The old content in the clipboard is replaced). If those two positions are the same, clipboard will be cleared.

Please note that , if any letter except 'L' , 'R' and 'D' is inputted when copy status is "START", copy status will changed into "NOTHING" immediately, not affecting the inputted letter taking its own effect as mention above. If 'D' is inputted when copy status is "START", copy status will changed into "NOTHING" immediately, and the letters between current caret position and "copy position 1" will be deleted.

'V': Paste the content in the clipboard into the right of the caret. If there is nothing in the clipboard, nothing happens. In "insertion mode", the pasted content is inserted. If it's in "overwrite mode" and there are k letters in the clipboard, then k letters will be overwrote. In "overwrite mode", if the number of letters on the right side of the caret is less then k, those letters will also all be replaced by the letters in the clipboard. After the paste operation, the caret moves to the right of the last pasted letter.

The content of the text line will never exceed M letters. Any input which will cause the content exceed M letters must be ignored. Especially, when you paste, you either paste all content in the clipboard, or paste nothing due to the text length limit.

输入

The first line of the input is a integer T(T <= 20), meaning that there are T test cases. The T lines follow, and each line is a test case.

For each test case:

A integer M (0 <= M <= 10,000) goes first ,meaning the text length limitation. Then some letters follow, describing what Bad Boss inputs. The total number of letters in one test case is no more than 10,000.

输出

For each test case, print the result which Bad Boss gets. If the result is nothing, print "NOTHING".

样例输入
8
100 abcdeLCLLD
5 abcLkjff
15 abcBBdeLLDDxzDDDDRRRR
25 abcdefgLLLSxyzSLLku
20 abcdefgLLCkLLCRRRRRCLV
20 abcdefgLLCkLLCRRRRCLLLSV
30 abcdeCLLCRRVCLRCabVkz
10 abcBBBLB
样例输出
abe
abkjc
axz
abcdxkuyz
abcdekfekfgg
abcdeekfg
abcdedeabkz
NOTHING 题意:比较复杂,建议看英文,大致是要写一个文本编辑器,像记事本一样的东西
题解:虽说看上去模拟好像过不了,然而模拟是可以过得,然而我这个大渣渣搞了两小时都没有AC,连累队友了TAT
可以用链表模拟也可以用数组模拟
给一下我的WA的代码吧。。。
 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} const int N = , M = ;
struct CHAR {
char ch;
int Pre, Nex;
} Arr[M];
int Tot, Pos, Len;
int n;
// Mode : 0 -> insert 1 -> Cover
int WorkLength;
char Data[N];
int Mode, CopyPos, CopyLength;
char Clipboard[N]; inline void Solve(); inline void Input() {
int TestNumber;
scanf("%d", &TestNumber);
while(TestNumber--) {
scanf("%d", &n);
scanf("%s", Data+);
WorkLength = strlen(Data+);
Solve();
}
} inline void Insert(char x) {
if(Mode == ) {
// Insert
if(Len+ > n) return;
Tot++;
Arr[Tot].ch = x;
Arr[Tot].Pre = Pos, Arr[Tot].Nex = Arr[Pos].Nex;
int t = Arr[Pos].Nex;
Arr[t].Pre = Tot, Arr[Pos].Nex = Tot;
Pos = Tot;
Len++;
} else {
// Cover
if(Arr[Pos].Nex == -) return;
Pos = Arr[Pos].Nex;
Arr[Pos].ch = x;
}
} inline void LeftMove() {
if(Arr[Pos].Pre == -) return;
Pos = Arr[Pos].Pre;
} inline void RightMove() {
if(Arr[Pos].Nex == -) return;
Pos = Arr[Pos].Nex;
} inline void DeleteNext() {
if(Arr[Pos].Nex == -) return;
int t = Arr[Pos].Nex;
Arr[Pos].Nex = Arr[t].Nex;
if(Arr[t].Nex != -) Arr[Arr[t].Nex].Pre = Pos;
Len--;
} inline void DeleteThis() {
if(Pos <= ) return;
int x = Arr[Pos].Pre, y = Arr[Pos].Nex;
if(x != ) Arr[x].Nex = y;
if(y != ) Arr[y].Pre = x;
Pos = x;
Len--;
} inline int FindPos() {
int Cnt = ;
for(int x = ; x != Pos; x = Arr[x].Nex) Cnt++;
return Cnt;
} inline int FindPos(int Num) {
int x = ;
For(i, , Num) x = Arr[x].Nex;
return x;
} inline void CopyWork() {
if(CopyPos == -) CopyPos = FindPos();
else {
int x = CopyPos, y = FindPos();
CopyPos = -;
if(x < y) {
x = FindPos(x);
y = Pos;
} else {
y = FindPos(x);
x = Pos;
}
CopyLength = ;
while(x != y) {
x = Arr[x].Nex;
Clipboard[++CopyLength] = Arr[x].ch;
}
}
} inline void Delete() {
int x = CopyPos, y = FindPos();
CopyPos = -;
Len -= max(x, y)-min(x, y);
if(x < y) {
x = FindPos(x);
y = Pos;
} else {
y = FindPos(x);
x = Pos;
}
Arr[x].Nex = Arr[y].Nex;
if(Arr[y].Nex != -) Arr[Arr[y].Nex].Pre = x; } inline void Paste() {
if(Len+CopyLength > n) return;
For(i, , CopyLength) Insert(Clipboard[i]);
if(Mode == ) Len += CopyLength;
} inline void Solve() {
CopyPos = -;
Arr[].Pre = Arr[].Nex = -, Tot = Len = , Pos = ;
Mode = , CopyLength = ;
clr(Clipboard, ); For(i, , WorkLength) {
char x = Data[i]; if(CopyPos != - && x != 'L' && x != 'R' && x != 'D' && x != 'C') CopyPos = -; if(x >= 'a' && x <= 'z') Insert(x);
else if(x == 'L') LeftMove();
else if(x == 'R') RightMove();
else if(x == 'S') Mode ^= ;
else if(x == 'D') {
if(CopyPos != -) Delete();
else DeleteNext();
} else if(x == 'B') DeleteThis();
else if(x == 'C') CopyWork();
else if(x == 'V') Paste();
} if(Len > ) {
int x = Arr[].Nex;
while(x != -) {
printf("%c", Arr[x].ch);
x = Arr[x].Nex;
}
puts("");
} else puts("NOTHING");
} int main() {
#ifndef ONLINE_JUDGE
SetIO("B");
#endif
Input();
//Solve();
return ;
}

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

  1. ACM-ICPC国际大学生程序设计竞赛北京赛区&lpar;2015&rpar;网络赛 Scores

    #1236 : Scores 时间限制:4000ms 单点时限:4000ms 内存限制:256MB 描述 Kyle is a student of Programming Monkey Element ...

  2. ACM-ICPC国际大学生程序设计竞赛北京赛区&lpar;2015&rpar;网络赛

    #1235 : New Teaching Buildings 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 Thanks to the generous finance ...

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

    #1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...

  4. ACM-ICPC国际大学生程序设计竞赛北京赛区&lpar;2016&rpar;网络赛 A Simple Job

    描述 Institute of Computational Linguistics (ICL), Peking University is an interdisciplinary institute ...

  5. ACM-ICPC国际大学生程序设计竞赛北京赛区&lpar;2016&rpar;网络赛 The Book List

    描述 The history of Peking University Library is as long as the history of Peking University. It was b ...

  6. hihoCoder 1389 Sewage Treatment 【二分&plus;网络流&plus;优化】 &lpar;ACM-ICPC国际大学生程序设计竞赛北京赛区&lpar;2016&rpar;网络赛&rpar;

    #1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people coul ...

  7. hihoCoder 1391 Countries 【预处理&plus;排序&plus;堆】 &lpar;ACM-ICPC国际大学生程序设计竞赛北京赛区&lpar;2016&rpar;网络赛&rpar;

    #1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...

  8. hihoCoder 1392 War Chess 【模拟】 &lpar;ACM-ICPC国际大学生程序设计竞赛北京赛区&lpar;2016&rpar;网络赛&rpar;

    #1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...

  9. ACM-ICPC国际大学生程序设计竞赛北京赛区&lpar;2017&rpar;网络赛 题目9 &colon; Minimum

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...

随机推荐

  1. 第二百一十九天 how can I 坚持

    今天好冷,白天在家待了一天,晚上,老贾生日,生日快乐,去海底捞吃了个火锅,没感觉呢. 今天还发现了个好游戏,纪念碑谷,挺新颖,就是难度有点大了. 好累.睡觉,明天想去爬山啊,可是该死的天气.

  2. 关于jsb中js与c&plus;&plus;的相互调用

    1.js调用c++函数 在c++中声明函数,名为functionCpp,通过spidermonkey中jsapi的JS_DefineFunction绑定一个js函数,名为functionJS,此函数名 ...

  3. cocos2d-x 3&period;0游戏实例学习笔记《卡牌塔防》第七步---英雄要升级&amp&semi;amp&semi;属性--解析csv配置文件

    /* 说明: **1.本次游戏实例是<cocos2d-x游戏开发之旅>上的最后一个游戏,这里用3.0重写并做下笔记 **2.我也问过木头本人啦.他说:随便写,第一别全然照搬代码:第二能够说 ...

  4. maven打包成第三方jar包且把pom依赖包打入进来

    <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId& ...

  5. java工具类&lpar;一&rpar;之服务端java实现根据地址从百度API获取经纬度

    服务端java实现根据地址从百度API获取经纬度 代码: package com.pb.baiduapi; import java.io.BufferedReader; import java.io. ...

  6. python3 词法拆分

    1.可以利用translate+string模块 2.可以利用jieba进行分词(结巴分词会分成词,但是我需要断句,所以这里不用) 3.利用python内置函数解决 仅仅只列出第3种方法,其他两种方法 ...

  7. &period;net4&period;0调用非托管DLL的异常捕获

    转发: 由于有些非托管的DLL内部异常未有效处理,当托管程序调用到这样的DLL时,就引起托管程序意外退出. 托管程序使用通常的捕获try……catch块不起作用.原因是.NET 4.0里新的异常处理机 ...

  8. 为什么要使用mybaits

    通常在项目开发过程中,有很多代码是重复的,固定不变的.为了提升开发效率,可将这些 固定不变的代码提取出来,生成class文件,将class文件打jar包,基于框架开发. mybaits是一个ORM框架 ...

  9. find -size 查出指定文件大小的命令

    find -size n [c] 查找n值大小的文件,默认单位是块(1块=512字节) 1. 查找大于1500字节的文件 find ~ -size +1500c 2. 查找等于1500字节的文件 fi ...

  10. Java并发编程——阻塞队列BlockingQueue

    Java 并发编程系列文章 Java 并发基础——线程安全性 Java 并发编程——Callable+Future+FutureTask java 并发编程——Thread 源码重新学习 java并发 ...