hihocoder #1228 : Mission Impossible 6 模拟
来源:互联网 发布:数据挖掘导论 范明 编辑:程序博客网 时间:2024/04/29 01:32
总结 :1 .题意理解
2. 插入要从后往前枚举更新, 删除要从前往后枚举更新数据结构没学好。。。。
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#define maxn 100005using namespace std;int flagOve;int po, copyPoStart, copyPoEnd;char ans[maxn];int l, m;char update[maxn];char cop[maxn];int copLen;void copyEnd()//OK{ int L = min(copyPoStart, copyPoEnd), R = max(copyPoStart, copyPoEnd); copLen = 0; for(int i = L; i < R; i++) cop[copLen++] = ans[i]; copyPoStart = -1;}void L()//OK{ if(copyPoEnd > 0) copyPoEnd--; if(po > 0) po--;}void R()//Ok{ if(copyPoEnd < l) copyPoEnd++; if(po < l) po++;}void S()//OK{ copyPoStart = -1; flagOve ^= 1;}void D()//OK{ if(copyPoStart != -1) { int L = min(copyPoStart, copyPoEnd), R = max(copyPoStart, copyPoEnd); for(int i = R, j = L; i < l; i++, j++) ans[j] = ans[i]; l -= (R - L); po = L; } else{ for(int i = po; i < l - 1; i++) ans[i] = ans[i + 1]; if(po != l) l--; } copyPoStart = -1;}void B()//OK{ copyPoStart = -1; int pre = po - 1; if(pre == -1)return ; else { for(int i = pre; i < l - 1; i++) ans[i] = ans[i + 1]; po--; l--; }}void C() //OK{ if(copyPoStart != -1) copyEnd(); else { copyPoStart = po; copyPoEnd = po; }}void V()//OK{ copyPoStart = -1; if(flagOve) { if(copLen + po <= m) { for(int i = po; i < copLen + po; i++) ans[i] = cop[i - po]; l = max(l, copLen + po); po += copLen; } } else { if(copLen + l <= m) { for(int i = l, j = copLen + l; i >= po; i--, j--) ans[j] = ans[i]; //for(int i = po, j = copLen + po; i < l; i++, j++) ans[j] = ans[i]; for(int i = po; i < po + copLen; i++) ans[i] = cop[i - po]; l += copLen; po += copLen; } }}void low(char ss){ copyPoStart = -1; if(flagOve) { if(po != l){ ans[po] = ss; po++; } else if(l != m) { ans[po] = ss; po++; l++; } } else { if(l == m)return; for(int i = l; i > po; i--) ans[i] = ans[i - 1]; ans[po] = ss; l++; po++; }}void init(){ copyPoStart = -1; po = 0; l = 0; copLen = 0; flagOve = 0;}int main(){ int t; scanf("%d", &t); while(t--) { scanf("%d %s", &m, update); init(); for(int i = 0; update[i]; i++) { if(update[i] >= 'a' && update[i] <= 'z') low(update[i]); else if(update[i] == 'L') L(); else if(update[i] == 'R') R(); else if(update[i] == 'S') S(); else if(update[i] == 'D') D(); else if(update[i] == 'B') B(); else if(update[i] == 'C') C(); else if(update[i] == 'V') V(); } if(l == 0) printf("NOTHING\n"); else { for(int i = 0; i < l; i++)printf("%c", ans[i]); printf("\n"); } } return 0;}
0 0
- hihoCoder 1228 Mission Impossible 6(模拟)
- hihocoder #1228 : Mission Impossible 6 模拟
- Hihocoder 1228 Mission Impossible 6
- hihocoder 1228 Mission Impossible 6
- hihoCoder 1228 Mission Impossible 6
- hihocoder 1228 Mission Impossible 6(模拟文本编辑器)
- hihoCoder 1228 Mission Impossible 6 2015北京网络赛 大模拟
- hihocoder 1228 Mission Impossible 6 一道写的我蛋碎的模拟题
- hiho 1228 Mission Impossible 6(模拟)
- hihocoder 1228 Mission Impossible 6(2015北京网赛 B)
- hihoCoder 1228 Mission Impossible 6(rope大法)
- hiho 1228(Mission Impossible 6-模拟文本编辑器)
- hiho 1228 Mission Impossible 6
- 2015ACM北京网赛B题 hihoCoder#1228 Mission Impossible 6
- 2015 网赛 北京 - B Mission Impossible 6 模拟
- hiho 1228 : Mission Impossible 6,北京网络赛B题
- 2015年ACM北京网络赛 B题Mission Impossible 6-链表模拟
- 2015北京网赛 Mission Impossible 6
- ubuntu下怎样创建桌面快捷方式
- 简谈java中的阻塞非阻塞与同步异步
- 一篇不错的v4l2 (实用)
- GCD是否创建线程总结
- Android学习之Activity深入
- hihocoder #1228 : Mission Impossible 6 模拟
- 【论小技巧的自我修养】(1)论模的优化
- 献给一直在打拼的人
- 209. Minimum Size Subarray Sum
- 转自:数据有意思;数据清洗的经验
- OpenCV学习笔记(1)-----OpenCV 3.1.0环境安装
- theano学习初步(一)
- 第一个工作项目(1)- 忆往昔
- MAC使用brew安装nginx+php+mysql环境