Parencodings
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 25010   Accepted: 14745

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

Source

代码:
 #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.size();
int cnt=;
for(int i=;i<num;i++)
{
if(s[i]==')')
{
cnt++;
int flag=;
int sum=;
for(int j=i-;j>=;j--)
{
if(flag==)
break;
if(s[j]=='(')
{
sum++;
flag-=;
}
else if(s[j]==')')
flag+=;
}
if(cnt!=n)
printf("%d ",sum);
else printf("%d\n",sum);
}
}
}
return ;
}

poj1068 模拟的更多相关文章

  1. [ACM_模拟] POJ1068 Parencodings (两种括号编码转化 规律 模拟)

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

  2. poj1068解题报告(模拟类)

    POJ 1068,题目链接http://poj.org/problem?id=1068 题意: 对于给出给出的原括号串S,对应两种数字密码串P.W: S         (((()()()))) P- ...

  3. [poj1068]Parencodings_模拟

    Parencodings 题目大意:给你一个P序列,表示从左到右的右括号左边有多少左括号,求M序列. 注释:M序列定义为每一个右括号左边最近的没有被之前的右括号匹配的括号之间,有多少已经匹配的括号队对 ...

  4. POJ1068 Parencodings(模拟)

    题目链接. 分析: 水题. #include <iostream> #include <cstdio> #include <cstring> using names ...

  5. POJ1068 --(模拟)

    这题是在看一个书的时候的一个例题,当时并不明白啥意思,于是便找了下原题,以前没在POJ上刷过,这是开了个头,以后努力刷这个网站 题目大概意思是:http://poj.org/problem?id=10 ...

  6. poj1068 【模拟】

    Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:  ...

  7. POJ-1068 Parencodings---模拟括号的配对

    题目链接: https://vjudge.net/problem/POJ-1068 题目大意: 给出一种括号序列的表示形式名叫P序列,规则是统计出每个右括号之前的左括号个数作为序列每项的值.然后要求你 ...

  8. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  9. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

随机推荐

  1. python最简单的http服务器

    人生苦短,我用python 今天有个需求就是简单的把自己的图片通过web共享,自然就想起了使用服务器了,在python下使用一个简单的服务器是非常方便的,用到标准库里面的SimpleHTTPServe ...

  2. u盘中放入大于4g单独文件失败解决

    u盘中文件格式通常为FAT32,需要转换为NTFS格式 在win7中cmd调出命令行,输入: convert H: /fs:ntfs (H为u盘位置)

  3. 阻止Ajax多次提交

    1.Ajax的abort() xhr = $.ajax({}) if (xhr){ xhr.abort(); } 2.通过在Ajax的beforeSend()方法以及complete()方法添加删除类 ...

  4. constructor

    function Person(name){ this.name = name; } Person.prototype = { constructor : Person, sayName : func ...

  5. BZOJ2597 [Wc2007]剪刀石头布(最小费用最大流)

    题目大概是说n个人两两进行比赛,问如何安排几场比赛的输赢使得A胜B,B胜C,C胜A这种剪刀石头布的三元组最多. 这题好神. 首先,三元组总共有$C_n^3$个 然后考虑最小化不满足剪刀石头布条件的三元 ...

  6. UpdatePanel的使用

    一.UpdatePanel的结构 <asp:ScriptManager ID="ScriptManager1" runat="server" > & ...

  7. adams/car 怎么进入template builder模块

    打开C:\Documents and Settings\Administrator文件夹下的acar.cfg文件,将 Desired user mode (standard/expert)ENVIRO ...

  8. 【原】iOS学习44之动画

    1. 简单动画 1> UIImageView GIF 动画 GIF图的原理是:获取图片,存储在图片数组中,按照图片数组的顺序将图片以一定的速度播放 UIImageView *showGifima ...

  9. H5 浏览器开发文档

    http://sja.co.uk/controlling-which-ios-keyboard-is-shown https://developer.apple.com/library/safari/ ...

  10. Android ListView item项 显示动画

    (1)使用LayoutAnimation 所谓的布局动画,其实就是为ViewGroup添加显示动画效果,主要用过LayoutAnimationController来控制实现.LayoutAnimati ...