参考链接:https://blog.csdn.net/SSLGZ_yyc/article/details/81700623 对顶栈的思想: 建立两个栈,栈A存储从序列开头到当前光标的位置的一段序列,栈B存储从光标到结尾的序列.这两个栈一共存储了整个序列. java版本代码 import java.util.Scanner; import java.util.Stack; public class Main { public static void main(String[] args) { in…
E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence…
用两个栈模拟: Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1913 Accepted Submission(s): 591 Problem Description Sample Input 8 I 2 I -1 I 1 Q 3 L D R Q 2 Sample Output 2 3 Hint The…
思路:刚开始用STL中的栈,一直RE……,之后改为手动模拟栈操作,在注意点细节就可以了!!! 代码如下: #include<cstdio> #include<cstring> #include<algorithm> #define M 1000001 using namespace std; int A[M],B[M],a[M],s[M],cur,x,q,l,r; char c; int main() { while(scanf("%d",&…
Problem Description Sample Input 8 I 2 I -1 I 1 Q 3 L D R Q 2 Sample Output 2 3 Hint The following diagram shows the status of sequence after each instruction: 题意:n个操作 5种操作,I x:该光标位置插入x并且光标后移 D :删除光标前的一个数 L :光标左移 R :光标右移 Q k:询问位置k之前的最大前缀和,k不会超过当前…