Parencodings
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 18785   Accepted: 11320

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
/*
* File: main.cpp
* Author: liaoyu <liaoyu@whu.edu.cn>
*
* Created on April 1, 2014, 5:34 PM
*/ #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <algorithm> #include<map>
using namespace std;
int p[];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
p[]=;
for(int i=;i<=n;i++){
scanf("%d",&p[i]);
}
for(int i=;i<=n;i++){
for(int k=;k<=i;k++){
if(p[i]-p[i-k]>=k){
printf("%d ",k);
break;
}
}
}
printf("\n");
}
return ;
}

poj1068的更多相关文章

  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---模拟括号的配对

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

  3. POJ-1068题

    下面的代码是北京大学Online Judge网站上1068题(网址:http://poj.org/problem?id=1068)的所写的代码. 该题的难点在于实现括号匹配,我在代码中采取用-1和1分 ...

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

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

  5. NUC_HomeWork1 -- POJ1068

    A - Parencodings Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Su ...

  6. poj1068 模拟

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

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

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

  8. POJ1068——Parencodings

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

  9. POJ1068 Parencodings(模拟)

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

随机推荐

  1. mybatis实战教程(mybatis in action)之九:mybatis 代码生成工具的使用

    mybatis 应用程序,需要大量的配置文件,对于一个成百上千的数据库表来说,完全手工配置,这是一个很恐怖的工作量. 所以mybatis 官方也推出了一个mybatis代码生成工具的jar包. 今天花 ...

  2. Troubleshooting a node by using the netapp SP

    Troubleshooting a node by using the SP When you encounter a problem with a node, you can use the SP ...

  3. Maven私有仓库搭建和使用

    下载和安装 下载地址: http://www.sonatype.com/nexus-repository-oss 安装: Linux版的无需安装,直接解压即可,然后进入bin目录下,运行./nexus ...

  4. Python六大开源框架对比:Web2py略胜一筹

    Python是一门动态.面向对象语言.其最初就是作为一门面向对象语言设计的,并且在后期又加入了一些更高级的特性.除了语言本身的设计目的之外,Python标准库也是值得大家称赞的,Python甚至还自带 ...

  5. Java与C++程序在编译和运行上的区别

    Java.C++都属于高级语言,而计算机能认识执行的只是机器码(即二进制),所以高级语言都必须经过直接或间接的转换成汇编以后,才能运行: 对于C/C++这类高级计算机语言,它们的编译器(例如Unix下 ...

  6. [Maven]Maven安装简述

    maven安装简述 1检查jdk安装 1.1cmd输入echo %JAVA_HOME%检查JAVA_HOME是否指向了正确的jdk安装目录 1.2cmd输入java-version检查window是否 ...

  7. subline

    快捷键(preference->key bindings): [ { "keys": ["ctrl+d"], "command": & ...

  8. 用delphi实现rar文件的解压的方法

    http://blog.csdn.net/ad_home/article/details/2818936 准备工作     下载winrar提供的动态链接库unrar.dll     http://w ...

  9. I'm an artist who loves linux (转)

    My father got me a computer for graduation with 512MB RAM and a Pentium processor. It came with Wind ...

  10. pip China

    建个文件 ~/.pip/pip.conf, 内容如下 [global] index-url = http://b.pypi.python.org/simple [install] use-mirror ...