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. 玩转Nuget服务器搭建(一)

    背景                                                                                      公司项目是分模块进行架构 ...

  2. SONY的几款秋季新品都还是很不错的

    年末的最后几个月,貌似SONY一口气发布你好几款新品,感觉都非常不错,貌似好久没有见到SONY这样的大批这么对胃口的产品了,这里简单的列举一下: 混合单元动铁动圈耳机XBA-H3 虽然动铁动圈混合式设 ...

  3. 设置并删除Dreamweaver自动生成的_notes文件夹

    在使用Dreamweaver做项目时站点下面的每个文件夹里面都会自动生成一个_notes文件夹,删除之后马上又会再次生成.最近做项目时,有童鞋一不小心把所有的_notes文件夹全部存回到SVN上面了, ...

  4. Delphi CRC算法, 不错

    http://www.cnblogs.com/tangqs/archive/2011/12/08/2280255.html

  5. iOS -- tableView顶部留白

    最近iOS 11 下来之后需要适配系统,故此测试系统发现同一种机器上tableView与顶部控件,或者导航栏之间的有大量的留白: 这个问题是有的界面有,有的界面无: 修改与导航栏或者其他控件之间的距离 ...

  6. java 中的VO,PO,DTO,DO对象

    经常会接触到VO,DO,DTO的概念,本文从领域建模中的实体划分和项目中的实际应用情况两个角度,对这几个概念进行简析. 得出的主要结论是:在项目应用中,VO对应于页面上需要显示的数据(表单),DO对应 ...

  7. nginx静态资源配置

    解决EE工程中静态文件显示问题 在工程中本地测试没有问题,发现使用nginx配置了路径的页面,会获取不到相应页面的静态文件问题 静态文件的路径类似为: http://localhost:8080/sa ...

  8. 2016.6.30 tomcat开启时,显示端口被占用,如何修改端口

    开启tomcat时,有时候会显示端口8080已占用,所以需要将端口改为其他值. 找到tomcat的server.xml文件,修改为8088,如图所示:

  9. /profile文件修改后立即生效

    修改profile etc/profile文件是只读的,直接用vi或gedit打开修改后是无法保存的.要修改profile,需要取得root权限,(使用gedit编辑) $sudo gedit /et ...

  10. FizzBuzz and Fibonacci优化

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...