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 ...
随机推荐
- spring所需包下载
1.进入http://repo.spring.io/webapp/search/artifact/选择artifacts,在搜过栏输入spring-framework,点击查询出来的表头artifac ...
- 总结使用Unity 3D优化游戏运行性能的经验
原地址:http://www.gameres.com/msg_221889.html 作者:Amir Fasshihi 流畅的游戏玩法来自流畅的帧率,而我们即将推出的动作平台游戏<Shadow ...
- 破解php-screw加密过的文件有效方法
今天终于搞定更改过密钥的php-screw解密问题,乐呵一下! 改进下 这样就可以解密任何加密过的PHP源码(包括更改过密钥的),解密的原理稍后具体列出,先说下如何加密 列出之前写使用php scre ...
- Ubuntu删除history记录
history -c就是清除本次登录到目前所执行的命令 转自: http://www.linuxdiyf.com/viewarticle.php?id=189355
- C++使用throw抛出异常
引用: c++ 使用throw抛出异常 抛出异常(也称为抛弃异常)即检测是否产生异常,在C++中,其采用throw语句来实现,如果检测到产生异常,则抛出异常.该语句的格式为:throw 表达式; ...
- Xenomai 安装准备工作
一些安装xenomai的参考资料: http://my.oschina.net/hevakelcj/blog/124290 http://blog.sina.com.cn/s/blog_60b9ee1 ...
- 【JAVA、C++】LeetCode 003 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- codeforces 489A.SwapSort 解题报告
题目链接:http://codeforces.com/problemset/problem/489/A 题目意思:给出一个 n 个无序的序列,问能通过两两交换,需要多少次使得整个序列最终呈现非递减形式 ...
- hdu 1272 小希的迷宫 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1272 第二条并查集,和畅通工程的解法类似.判断小希的迷宫不符合条件,即有回路.我的做法是,在合并两个集 ...
- Gym 100851E Easy Problemset (模拟题)
Problem E. Easy ProblemsetInput file: easy.in Output file: easy.outPerhaps one of the hardest problems ...