Parencodings
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 28860   Accepted: 16997

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 从别人的博客上学的:
https://www.cnblogs.com/--ZHIYUAN/p/5910981.html
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(){
int n,T;
scanf("%d",&T);
while(T--){
int q1,q2 = ;
string s;
scanf("%d",&n);
for(int i = ; i < n; i++){
scanf("%d",&q1);
q2 = q1 - q2;
while(q2--)
s += "(";
s += ")";
q2 = q1;
}
int num = s.length();
int cnt = ;
int sum;
for(int i = ; i < num; i++){
if(s[i] == ')'){
cnt++;
int flag = ;
sum = ;
for(int j = i - ; j >= ; j--){
if(flag == )
break;
if(s[j] == ')'){
flag += ;
}
else if(s[j] == '('){
flag -= ;
sum++;
}
}
if(cnt != n)
printf("%d ",sum);
else
printf("%d\n",sum);
} }
}
return ;
}

PO1068 Parencodings 模拟题的更多相关文章

  1. poj 1068 Parencodings 模拟题

    Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...

  2. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  3. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  4. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  5. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  6. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  7. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  8. cdoj 25 点球大战(penalty) 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

  9. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

随机推荐

  1. webpack始出来

    一直想好好整理一下webpack,现在就整理吧. 总结自己的实际搭建的整理情况,我还是要先对自己说一句,以后给文件夹起名字的时候不要用一些特殊的关键字,比如我在做这个demo的时候,我用的文件夹名称叫 ...

  2. django-admin和manage.py

    目录 一.Django内置命令选项 check dbshell diffsettings flush makemigrations migrate runserver shell startapp s ...

  3. vs + babelua + cocos2d-x

    https://blog.csdn.net/dugaoda/article/details/60467037 https://blog.csdn.net/taotanty/article/detail ...

  4. Nginx+uwsgi部署 Diango(生产环境)

    环境:CentOS6.5 + Nginx1.11.5 + Python3.5.2 1. 安装基础软件包 yum install -y zlib-devel bzip2-devel \ pcre-dev ...

  5. python3,打印一年的某一天是一年的第几天

    year = int(input('year:')) month = int(input('month:')) day = int(input('day:')) months = (0,31,59,9 ...

  6. ACM中的fread读入

    fread可以加快读入速度,尤其是读特大的二进制文件. #include <cctype> typedef long long LL; char buf[100000],*p1=buf,* ...

  7. 【转】使用STM32F4的CCM内存

    我们知道STM32F4当中有个CCM内存,如图所示,这个内存是挂在D总线上直接和内核相连,因此除了内核之外谁都不能访问,那么我们怎么将其利用起来呢?网上这个资料还真的很少,今天我就给大家分享一下,献给 ...

  8. 「HNOI2016」网络 解题报告

    「HNOI2016」网络 我有一个绝妙的可持久化树套树思路,可惜的是,它的空间是\(n\log^2 n\)的... 注意到对一个询问,我们可以二分答案 然后统计经过这个点大于当前答案的路径条数,如果这 ...

  9. [POI2007]ODW-Weights(贪心)

    在byteotian公司搬家的时候,他们发现他们的大量的精密砝码的搬运是一件恼人的工作.公司有一些固定容量的容器可以装这些砝码.他们想装尽量多的砝码以便搬运,并且丢弃剩下的砝码.每个容器可以装的砝码数 ...

  10. python爬虫解析库学习

    一.xpath库使用: 1.基本规则: 2.将文件转为HTML对象: html = etree.parse('./test.html', etree.HTMLParser()) result = et ...