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. js日常笔记

    写在前面: 在工作中,有时候会遇到一些零零碎碎的小知识点,虽然这些网上都可以查询到,但还是想把一些自己不是很熟悉的当做笔记记录下来,方便以后查询. 1.按钮隐藏/显示/可用/不可用 $("# ...

  2. centos iptables关于ping

    配置iptables策略后,一般来说INPUT都是DROP然后配置需要通过的 当执行: iptables -P INPUT DROP 后,机器就不能被ping通了! 因为icmp没有添加到规则中! 于 ...

  3. 数据块dump详解及大小表扫描过程

    http://blog.csdn.net/u013820054/article/details/40378233 http://blog.csdn.net/u013820054/article/cat ...

  4. UBI介绍

    转:http://blog.csdn.net/kickxxx/article/details/6707589 目录 Table of contents Big red note User-space ...

  5. kubernetes1.5.2--部署dashboard服务

    本文基于kubernetes 1.5.2版本编写 使用http方式访问api server的部署 cat dashboard-controller.yaml apiVersion: extension ...

  6. EarlyZ disable( earlyz失效

    There are a few ways to disable EarlyZ list here: Shader depth output disabled Alpha test with depth ...

  7. ElasticSearch 排序

    1.相关性排序 ElasticSearch为了按照相关性来排序,需要将相关性表示为一个数值,在 Elasticsearch 中, 相关性得分 由一个浮点数进行表示,并在搜索结果中通过 _score 参 ...

  8. Redis 命令二

    一.连接控制 QUIT 关闭连接 AUTH (仅限启用时)简单的密码验证 二.适合全体类型的命令 EXISTS key 判断一个键是否存在;存在返回 1;否则返回0; DEL key 删除某个key, ...

  9. 遗传算法解决TSP问题

    1实验环境 实验环境:CPU i5-2450M@2.50GHz,内存6G,windows7 64位操作系统 实现语言:java (JDK1.8) 实验数据:TSPLIB,TSP采样实例库中的att48 ...

  10. P6 EPPM 安装和配置指南

    In This Section Installation and Configuration Guide Manual Installation Guides P6 Professional Inst ...