【NOIP2017提高A组模拟8.10】文本编辑器
2017-08-11 22:36
399 查看
Description
Input
第一行是初始内容之后按照题目要求
Output
对于每个命令,按照要求输出Sample Input
goodykc11
I R u
I R l
L
L
L
L
R
D R
< R
D R
S
Sample Output
TT
T
T
T
T
T
F
T
T
goodluck
Solution
毒瘤显然可以用splay做,但是只有90分
100分必须线性做法
有一个比较简单的做法
左指针左边的维护一个栈,有指针右边的维护一个栈
中间的维护一个双向队列
是否翻转直接打标记
如果左指针跑到了有指针右边,就直接交换指针,并打交换标记
这不是唯一做法,但应该是细节最少最好做的做法
Code
#include<cstdio> #include<algorithm> #include<cstring> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) #define N 5010000 using namespace std; char s ; int a[N*2],b[2][N*2],re=0,rev=0,tot[2],l,r; int main() { scanf("%s\n",s+1); int n=strlen(s+1); fo(i,1+N,n+N) a[i]=s[i-N]; l=1+N,r=n+N; int ac;scanf("%d\n",&ac); for(;ac;ac--) { char ch;scanf("%c",&ch); if(ch=='<') { char W;scanf(" %c\n",&W); int y=W=='L'?0:1; if(re) y=1-y; if(y==0) { if(tot[y]>0) { if(rev) a[++r]=b[0][tot[0]],tot[0]--; else a[--l]=b[0][tot[0]],tot[0]--; printf("T\n"); } else printf("F\n"); } else { if(tot[y]<n) { if(tot[1]+tot[0]==n) re^=1; else { if(rev) b[1][++tot[1]]=a[l++]; else b[1][++tot[1]]=a[r--]; } printf("T\n"); } else printf("F\n"); } } if(ch=='>') { char W;scanf(" %c\n",&W); int y=W=='L'?0:1; if(re) y=1-y; if(y==0) { if(tot[y]<n) { if(tot[1]+tot[0]==n) re^=1; else { if(rev) b[0][++tot[0]]=a[r--]; else b[0][++tot[0]]=a[l++]; } printf("T\n"); } else printf("F\n"); } else { if(tot[y]>0) { if(rev) a[--l]=b[1][tot[1]],tot[1]--; else a[++r]=b[1][tot[1]],tot[1]--; printf("T\n"); } else printf("F\n"); } } if(ch=='I') { char W,c;scanf(" %c %c\n",&W,&c); int y=W=='L'?0:1; if(re) y=1-y; if(y==0) { tot[0]++;b[0][tot[0]]=c; } else { if(rev) a[--l]=c; else a[++r]=c; } n++; printf("T\n"); } if(ch=='D') { char W,c;scanf(" %c\n",&W); int y=W=='L'?0:1; if(re) y=1-y; if(y==0) { if(r-l+1) { if(rev) r--; else l++; n--; printf("T\n"); } else printf("F\n"); } else { if(tot[1]>0) { tot[1]--; printf("T\n"); } else printf("F\n"); } } if(ch=='R') { scanf("\n"); if(!re) rev^=1,printf("T\n"); else printf("F\n"); } if(ch=='S') { scanf("\n"); fo(i,1,tot[0]) printf("%c",b[0][i]); if(rev) fd(i,r,l) printf("%c",a[i]); else fo(i,l,r) printf("%c",a[i]); fd(i,tot[1],1) printf("%c",b[1][i]); printf("\n"); } } }
相关文章推荐
- 【JZOJ 5249】【NOIP2017提高A组模拟8.10】文本编辑器
- jzoj5249 【NOIP2017提高A组模拟8.10】文本编辑器 (序列修改类问题,数据结构)
- 【JZOJ5249】【NOIP2017提高A组模拟8.10】文本编辑器
- JZOJ5249. 【NOIP2017提高A组模拟8.10】文本编辑器
- 【NOIP2017提高A组模拟10.10】Graph
- 【NOIP2017提高A组模拟10.8】Star Way To Heaven(欧几里得距离最小生成树Prim做法)
- 【NOIP2017提高组模拟12.10】幻魔皇
- 【NOIP2017提高组模拟12.17】向再见说再见
- (前缀和排序)NOIP2017提高组模拟 Day1P1 小A的数学
- 【NOIP2017提高组模拟12.18】C
- NOIP2017提高A组模拟10.6】Biology
- 【NOIP2017提高组模拟12.10】神炎皇
- 【NOIP2017提高组模拟12.10】幻魔皇
- 【NOIP2017提高组模拟12.24】C
- 【NOIP2017提高A组模拟8.16】花花的森林
- 【NOIP2017提高A组模拟9.5】遥远的金字塔 斜率优化详解
- 【NOIP2017提高A组模拟9.14】生命之树 (dsu on tree+trie)
- 【NOIP2017提高A组模拟9.17】信仰是为了虚无之人
- 【NOIP2017提高组模拟6.25】总结
- 【NOIP2017提高组模拟6.27】B