Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 22764   Accepted: 13344

Description

Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: 
q By an integer sequence P = p1 p2...pn where pi is the number of left parentheses before the ith right parenthesis in S (P-sequence). 
q By an integer sequence W = w1 w2...wn where for each right parenthesis, say a in S, we associate an integer which is the number of right parentheses counting from the matched left parenthesis of a up to a. (W-sequence).

Following is an example of the above encodings:

	S		(((()()())))

P-sequence 4 5 6666

W-sequence 1 1 1456

Write a program to convert P-sequence of a well-formed string to the W-sequence of the same string. 

Input

The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case is an integer n (1 <= n <= 20), and the second line is the P-sequence of a well-formed string. It contains n positive integers, separated with blanks, representing the P-sequence.

Output

The output file consists of exactly t lines corresponding to test cases. For each test case, the output line should contain n integers describing the W-sequence of the string corresponding to its given P-sequence.

Sample Input

2
6
4 5 6 6 6 6
9
4 6 6 6 6 8 9 9 9

Sample Output

1 1 1 4 5 6
1 1 2 4 5 1 1 3 9
这道题很简单,一遍AC,用flag数组记录左括号的状态,当是1时已经匹配,当是0时未匹配,向前查找第一个未匹配的左括号,记录中间匹配的左括号的个数
 #include <iostream>
using namespace std; int main() {
int num;
int n;
int p[];
int flag[];
cin>>num;
for(int i=;i<num;i++){
cin>>n;
for(int j=;j<n;j++){
cin>>p[j];
flag[j]=;
}
for(int k=;k<n;k++){
int count=;
for(int m=p[k]-;m>=;m--){
if(flag[m]==){
cout<<count+<<" ";
flag[m]=;
break;
}else{
count++;
}
}
}
cout<<endl;
}
return ;
}

Parencodings - poj 1068的更多相关文章

  1. 模拟 POJ 1068 Parencodings

    题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...

  2. poj 1068 模拟

    题目链接 大概题意就是告诉你有个n个小括号,每一个")"左边有多少个"("都告诉你了,然后让你求出每一对括号之间有多少对括号(包含自己本身). 思路: 我先计算 ...

  3. POJ 1068 Parencodings【水模拟--数括号】

    链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...

  4. POJ 1068 Parencodings 模拟 难度:0

    http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...

  5. poj 1068 Parencodings(栈)

    题目链接:http://poj.org/problem?id=1068 思路分析:对栈的模拟,将栈中元素视为广义表,如 (((()()()))),可以看做 LS =< a1, a2..., a1 ...

  6. POJ 1068 Parencodings (类似括号的处理问题)

                                                                                                    Pare ...

  7. poj 1068 Parencodings(模拟)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...

  8. POJ 1068 Parencodings

    Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24932   Accepted: 14695 De ...

  9. [ACM] POJ 1068 Parencodings(模拟)

    Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19352   Accepted: 11675 De ...

随机推荐

  1. 【OpenJudge7624】【区间DP】山区建小学

    山区建小学 总时间限制: 1000ms 内存限制: 65536kB [描述] 政府在某山区修建了一条道路,恰好穿越总共m个村庄的每个村庄一次,没有回路或交叉,任意两个村庄只能通过这条路来往.已知任意两 ...

  2. SpringAop名词解释+基于xml的配置

    1,AOP名词解释 2,AOP演示 (1)导包: (2)准备目标对象 package com.songyan.service; import org.aspectj.lang.ProceedingJo ...

  3. 各种计算机编码与base64

    什么是base64,base64与Hex编码,ASCII编码,UTF-8编码都是什么关系 1 计算机开始之初,二进制 计算机所用的语言是什么呢?这个语言非常简单,只有0和1两种表示.0代表否,1代表是 ...

  4. What is the purpose of mock objects?

    Since you say you are new to unit testing and asked for mock objects in "layman's terms", ...

  5. 基于Rebound制造绚丽的动画效果-入门篇

    基于Rebound制造绚丽的动画效果-入门篇 Rebound是什么? Rebound是一个来自 Facebook 公司的 Java物理和动画库.Rebound spring 模型可用于创建动画,让你感 ...

  6. php安装扩展步骤(redis)

    星哥让装一个扩展,解决PDF抓PNG的问题,功能没有实现,有点小悲伤,但是还是学到点东西的. php安装扩展步骤(以redis为例) 前提注意:在自己的LINUX本机上一定要安装有redis软件,我之 ...

  7. Linux内核实践之工作队列

    工作队列(work queue)是另外一种将工作推后执行的形式,它和tasklet有所不同.工作队列可以把工作推后,交由一个内核线程去执行,也就是说,这个下半部分可以在进程上下文中执行.这样,通过工作 ...

  8. 静态代码检查工具-PMD刚開始学习的人入门篇

    前言: PMD是一款静态代码分析工具.它能够自己主动检測各种潜在缺陷以及不安全或未优化的代码. PMD很多其它地是集中在预先检測缺陷上.它提供了高度可配置的丰富规则集,用户能够方便配置对待特定项目使用 ...

  9. 系统封装 如何为原生PE集成软件

    1 我们首先集成Explorer.老外的BSExplorer比较好用,下载之后得到这些文件,不算太大.   2 这里需要注意,前一章讲解如何打造原生PE已经制作成了ISO,这里想要集成软件还需要回到刚 ...

  10. NinePatch

    将图片保存为扩展名为.9.png的格式直接放入Android Studio中的drawable文件夹,拖拉选择拉伸区域,如下图,即可制作出可拉伸背景