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. 3.1.g 找出在2009年秋季拥有最多选课人数的课程段

    3.1.g 找出在2009年秋季拥有最多选课人数的课程 3.1 使用大学模式,用SQL写出如下查询. g) 找出在2009年秋季拥有最多选课人数的课程段. 注:本题来自于 数据库系统概念 第六版 机械 ...

  2. WIN10 64位 JDK的安装

    因为电脑系统换掉,重装系统,重新配置了一下环境,安装JDK,现记录一下过程,以便下次查询使用. 官网下载JDK,地址:http://www.oracle.com/technetwork/java/ja ...

  3. etcd:从应用场景到实现原理的全方位解读

    随着CoreOS和Kubernetes等项目在开源社区日益火热,它们项目中都用到的etcd组件作为一个高可用强一致性的服务发现存储仓库,渐 渐为开发人员所关注.在云计算时代,如何让服务快速透明地接入到 ...

  4. Linux命令基本格式

    1 起始符td@td-Lenovo-IdeaPad-Y410P:~$ 第一个td表示当前登录管理员名,中间@无实际意义,td-Lenovo-IdeaPad-Y410P表示主机名,-表示当前所在目录(h ...

  5. 安卓查看包名,activity方法

    https://www.cnblogs.com/wangcp-2014/p/6144530.html 一.有源码情况 直接打开AndroidManifest.xml文件,找到包含android.int ...

  6. DEDECMS首页和列表页调用单个图片集里的多张图片

    /**DEDECMS首页和列表页调用单个图片集里的多张图片 function Getimg($aid,$imgwith=110,$imgheight=110,$num=0) { global $dsq ...

  7. Unitity 常用工具类

    ylbtech-Unitity_C#: Unitity 常用代码 1.A,效果图返回顶部   1.B,源代码返回顶部 1,日期字符串 using System; using System.Xml; / ...

  8. Java源码阅读HashMap

    1类签名与注释 public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cl ...

  9. spring boot 引用外部配置文件

    java -jar xx.jar -Dspring.config.location=/data/apps/xx/application-prod.properties

  10. m 调用传参图片切换

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...