ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6
#1228 : Mission Impossible 6
描述
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的更多相关文章
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 Scores
#1236 : Scores 时间限制:4000ms 单点时限:4000ms 内存限制:256MB 描述 Kyle is a student of Programming Monkey Element ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛
#1235 : New Teaching Buildings 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 Thanks to the generous finance ...
- hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 A Simple Job
描述 Institute of Computational Linguistics (ICL), Peking University is an interdisciplinary institute ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 The Book List
描述 The history of Peking University Library is as long as the history of Peking University. It was b ...
- hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people coul ...
- hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...
- hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum
时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...
随机推荐
- Leetcode 之Populating Next Right Pointers in Each Node II(51)
void connect(TreeLinkNode *root) { while (root) { //每一层循环时重新初始化 TreeLinkNode *prev = nullptr; TreeLi ...
- Coursera台大机器学习课程笔记14 -- Validation
这节课是接着上节的正则化课程的,目的也是为了防止overfitting. 第一小节讲了模型的选择,前面讲了很多模型,那么如何做出正确的选择呢?我们的目标是选择最小的Eout目标函数.首先应避免视觉化选 ...
- AspectJ报错:error at ::0 can't find referenced pointcut XXX
今天在使用AspectJ进行注解切面时,遇到了一个错误. 切点表达式就是无法识别——详细报错信息如下: Exception in thread "main" org.springf ...
- Tushare的安装
TuShare是一个免费.开源的python财经数据接口包.主要实现对股票等金融数据从数据采集.清洗加工到数据存储的过程,能够为金融分析人员提供快速.整洁.和多样的便于分析的数据. 考虑到python ...
- 配置oss bucket cors
到bucket中属性中选择跨越设置,点击添加规则会看到以下界面: 对应的输入如上即可.
- Eclipse常用快捷键与代码模板
Eclipse常用快捷键汇总 Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率.Eclipse中有如下一些和编辑相关的快捷键.1. [ALT+/]此快捷键为用户编 ...
- iOS 拍照中加入GPS和具体地理位置
最近有一个需求,要求用手机拍个照片,并切需要拍摄时间,拍摄gps,拍摄具体街道信息. 首先要感谢PhotoGPSdemo的作者,你可以到这里下载demo http://www.cocoachina.c ...
- Java for LeetCode 072 Edit Distance【HARD】
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...
- ASP.NET SignalR 与LayIM配合,轻松实现网站客服聊天室(二) 实现聊天室连接
上一篇已经简单介绍了layim WebUI即时通讯组件和获取数据的后台方法.现在要讨论的是SingalR的内容,之前都是直接贴代码.那么在贴代码之前先分析一下业务模型,顺便简单讲一下SingalR里的 ...
- Linux多台服务器之间的文件共享
由于项目有个图片上传和导入导出的模块,所以当项目通过集群方式部署的时候就要考虑文件共享问题. 文件共享要么就是通过统一的文件系统来管理,要么就是在系统之间做文件共享,前者扩展性比较好,可以随时随地加服 ...