Parencodings
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 20679   Accepted: 12436

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<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int p[] , w[] ;
int n ;
char s[] ; void convert1 ()
{
int k = ;
for (int i = ; i < p[] ; i++)
s[k++] = '(' ;
s[k++] = ')' ;
for (int i = ; i < n ; i++) {
for (int j = ; j < p[i] - p[i - ]; j++) {
s[k++] = '(' ;
}
s[k++] = ')' ;
}
s[k] = '\0' ;
// puts (s) ;
}
void convert2 ()
{
int l , r ;
int k = ;
for (int i = ; s[i] != '\0' ; i++) {
if (s[i] == ')') {
l = ;
r = ;
for (int j = i - ; j >= ; j--) {
if (s[j] == ')' )
r++ ;
else
l++ ;
if (l == r)
break ;
}
w[k++] = r;
}
}
for (int i = ; i < n ; i++) {
printf ("%d" , w[i]) ;
if (i != n - )
printf (" ") ;
}
puts ("") ;
}
int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
int T ;
scanf ("%d" , &T) ;
while (T--) {
scanf ("%d" , &n) ;
for (int i = ; i < n ; i++)
scanf ("%d" , &p[i]) ;
convert1 () ;
convert2 () ;
}
}

Parencodings(imitate)的更多相关文章

  1. [POJ1068]Parencodings

    [POJ1068]Parencodings 试题描述 Let S = s1 s2...s2n be a well-formed string of parentheses. S can be enco ...

  2. 模拟 POJ 1068 Parencodings

    题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...

  3. Parencodings 分类: POJ 2015-06-28 22:00 7人阅读 评论(0) 收藏

    Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22757   Accepted: 13337 De ...

  4. hdu 1361 Parencodings 简单模拟

    Parencodings 题意: 由括号序列S可经P规则和W规则变形为P序列和W序列. p规则是:pi是第i个右括号左边的左括号的数: w规则是:wi是第i右括号与它匹配的左括号之间右括号的数(其中包 ...

  5. POJ 1068 Parencodings

    Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24932   Accepted: 14695 De ...

  6. Poj OpenJudge 1068 Parencodings

    1.Link: http://poj.org/problem?id=1068 http://bailian.openjudge.cn/practice/1068 2.Content: Parencod ...

  7. POJ1068——Parencodings

    Parencodings Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encode ...

  8. PO1068 Parencodings 模拟题

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

  9. Hdu1361&&Poj1068 Parencodings 2017-01-18 17:17 45人阅读 评论(0) 收藏

    Parencodings Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

随机推荐

  1. java并发:获取线程执行结果(Callable、Future、FutureTask)

    初识Callable and Future 在编码时,我们可以通过继承Thread或是实现Runnable接口来创建线程,但是这两种方式都存在一个缺陷:在执行完任务之后无法获取执行结果.如果需要获取执 ...

  2. 教你用netstat-实践案例

    netstat命令的功能是显示网络连接.路由表和网络接口信息,可以让用户得知目前都有哪些网络连接正在运作. 该命令的一般格式为: netstat [选项] 命令中各选项的含义如下: -a 显示所有so ...

  3. KK录像机破解补丁

    KK录像机是由杭州凯凯科技有限公司出品的免费的集游戏录像.视频录制.视频剪辑.添加字幕.添加音乐等功能于一体的高清视频录制软件.操作简单,且兼容录制所有游戏视频,是玩家分享精彩的工具. KK VIP功 ...

  4. 更改PATH后,别忘了及时重启或刷新

    在windows环境下配了MinGW gcc编译器,结果编译时总提示找不到头文件.第一反应就是更改环境变量,但是将gcc目录添加到PATH中,再次运行编译依旧报错.多方查找后发现这样一句话:PATH在 ...

  5. iOS7(iPhone4)button不能改变button的title

    最近整了个高端的iPhone4测试机,系统是iOS7.1,测出一个问题,两个button,第二个的enable为NO,点击第一个button,第二个的title改变,然而在iPhone4上并不能运行, ...

  6. Html设置图标icon

    html head添加: <link rel="icon" href="/favicon.ico" type="image/x-icon&quo ...

  7. shiro 与 web 的结合

    本次使用的jar包为 shiro-core-.jar shiro-web-.jar 从Shiro 1.2开始引入了Environment/WebEnvironment的概念,即由它们的实现提供相应的S ...

  8. Java基础-被final修饰的引用变量的指向

    final修饰的引用变量一旦初始化赋值之后就不能再指向其他的对象,那么该引用变量指向的对象的内容可变吗?看下面这个例子: public class Test { public static void ...

  9. 未能加载文件或程序集“EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”

     未能加载文件或程序集“EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089” 使用nu ...

  10. json2form已改名为AForm

    相信大部分程序员都接触过表单,表单是收集用户输入的不二之选,但是表单的开发又是最繁琐.最复杂的,简单地说,开发表单你需要涉及到很多知识: 布局,表单如何布局排版,看起来最清晰整洁,且符合用户体验 控件 ...