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的代码吧。。。1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <deque> 6 #include <vector> 7 #include <queue> 8 #include <iostream> 9 #include <algorithm> 10 #include <map> 11 #include <set> 12 #include <ctime> 13 using namespace std; 14 typedef long long LL; 15 typedef double DB; 16 #define For(i, s, t) for(int i = (s); i <= (t); i++) 17 #define Ford(i, s, t) for(int i = (s); i >= (t); i--) 18 #define Rep(i, t) for(int i = (0); i < (t); i++) 19 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--) 20 #define rep(i, x, t) for(int i = (x); i < (t); i++) 21 #define MIT (2147483647) 22 #define INF (1000000001) 23 #define MLL (1000000000000000001LL) 24 #define sz(x) ((int) (x).size()) 25 #define clr(x, y) memset(x, y, sizeof(x)) 26 #define puf push_front 27 #define pub push_back 28 #define pof pop_front 29 #define pob pop_back 30 #define ft first 31 #define sd second 32 #define mk make_pair 33 inline void SetIO(string Name) { 34 string Input = Name+".in", 35 Output = Name+".out"; 36 freopen(Input.c_str(), "r", stdin), 37 freopen(Output.c_str(), "w", stdout); 38 } 39 40 const int N = 10010, M = 1000010; 41 struct CHAR { 42 char ch; 43 int Pre, Nex; 44 } Arr[M]; 45 int Tot, Pos, Len; 46 int n; 47 // Mode : 0 -> insert 1 -> Cover 48 int WorkLength; 49 char Data[N]; 50 int Mode, CopyPos, CopyLength; 51 char Clipboard[N]; 52 53 inline void Solve(); 54 55 inline void Input() { 56 int TestNumber; 57 scanf("%d", &TestNumber); 58 while(TestNumber--) { 59 scanf("%d", &n); 60 scanf("%s", Data+1); 61 WorkLength = strlen(Data+1); 62 Solve(); 63 } 64 } 65 66 inline void Insert(char x) { 67 if(Mode == 0) { 68 // Insert 69 if(Len+1 > n) return; 70 Tot++; 71 Arr[Tot].ch = x; 72 Arr[Tot].Pre = Pos, Arr[Tot].Nex = Arr[Pos].Nex; 73 int t = Arr[Pos].Nex; 74 Arr[t].Pre = Tot, Arr[Pos].Nex = Tot; 75 Pos = Tot; 76 Len++; 77 } else { 78 // Cover 79 if(Arr[Pos].Nex == -1) return; 80 Pos = Arr[Pos].Nex; 81 Arr[Pos].ch = x; 82 } 83 } 84 85 inline void LeftMove() { 86 if(Arr[Pos].Pre == -1) return; 87 Pos = Arr[Pos].Pre; 88 } 89 90 inline void RightMove() { 91 if(Arr[Pos].Nex == -1) return; 92 Pos = Arr[Pos].Nex; 93 } 94 95 inline void DeleteNext() { 96 if(Arr[Pos].Nex == -1) return; 97 int t = Arr[Pos].Nex; 98 Arr[Pos].Nex = Arr[t].Nex; 99 if(Arr[t].Nex != -1) Arr[Arr[t].Nex].Pre = Pos; 100 Len--; 101 } 102 103 inline void DeleteThis() { 104 if(Pos <= 0) return; 105 int x = Arr[Pos].Pre, y = Arr[Pos].Nex; 106 if(x != 0) Arr[x].Nex = y; 107 if(y != 0) Arr[y].Pre = x; 108 Pos = x; 109 Len--; 110 } 111 112 inline int FindPos() { 113 int Cnt = 0; 114 for(int x = 0; x != Pos; x = Arr[x].Nex) Cnt++; 115 return Cnt; 116 } 117 118 inline int FindPos(int Num) { 119 int x = 0; 120 For(i, 1, Num) x = Arr[x].Nex; 121 return x; 122 } 123 124 inline void CopyWork() { 125 if(CopyPos == -1) CopyPos = FindPos(); 126 else { 127 int x = CopyPos, y = FindPos(); 128 CopyPos = -1; 129 if(x < y) { 130 x = FindPos(x); 131 y = Pos; 132 } else { 133 y = FindPos(x); 134 x = Pos; 135 } 136 CopyLength = 0; 137 while(x != y) { 138 x = Arr[x].Nex; 139 Clipboard[++CopyLength] = Arr[x].ch; 140 } 141 } 142 } 143 144 inline void Delete() { 145 int x = CopyPos, y = FindPos(); 146 CopyPos = -1; 147 Len -= max(x, y)-min(x, y); 148 if(x < y) { 149 x = FindPos(x); 150 y = Pos; 151 } else { 152 y = FindPos(x); 153 x = Pos; 154 } 155 Arr[x].Nex = Arr[y].Nex; 156 if(Arr[y].Nex != -1) Arr[Arr[y].Nex].Pre = x; 157 158 } 159 160 inline void Paste() { 161 if(Len+CopyLength > n) return; 162 For(i, 1, CopyLength) Insert(Clipboard[i]); 163 if(Mode == 0) Len += CopyLength; 164 } 165 166 inline void Solve() { 167 CopyPos = -1; 168 Arr[0].Pre = Arr[0].Nex = -1, Tot = Len = 0, Pos = 0; 169 Mode = 0, CopyLength = 0; 170 clr(Clipboard, 0); 171 172 173 For(i, 1, WorkLength) { 174 char x = Data[i]; 175 176 if(CopyPos != -1 && x != 'L' && x != 'R' && x != 'D' && x != 'C') CopyPos = -1; 177 178 if(x >= 'a' && x <= 'z') Insert(x); 179 else if(x == 'L') LeftMove(); 180 else if(x == 'R') RightMove(); 181 else if(x == 'S') Mode ^= 1; 182 else if(x == 'D') { 183 if(CopyPos != -1) Delete(); 184 else DeleteNext(); 185 } else if(x == 'B') DeleteThis(); 186 else if(x == 'C') CopyWork(); 187 else if(x == 'V') Paste(); 188 } 189 190 if(Len > 0) { 191 int x = Arr[0].Nex; 192 while(x != -1) { 193 printf("%c", Arr[x].ch); 194 x = Arr[x].Nex; 195 } 196 puts(""); 197 } else puts("NOTHING"); 198 } 199 200 int main() { 201 #ifndef ONLINE_JUDGE 202 SetIO("B"); 203 #endif 204 Input(); 205 //Solve(); 206 return 0; 207 }