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. C# WinForm 禁止最大化、最小化、双击标题栏、双击图标等操作(转载)

    protected override void WndProc(ref Message m) { if (m.Msg==0x112) { switch ((int) m.WParam) { //禁止双 ...

  2. Keep-Alive 总结

    一.简介 Keep-Alive是http请求头信息中的一个配置参数,开启之后俗称保持HTTP长连接,HTTP 1.0和HTTP 1.1都支持,HTTP1.0中该属性默认是关闭的,可在头信息中配置开启( ...

  3. Inno Setup制作安装包的几个问题

    1. 卸载时,如何判断应用程序是否运行    InnoSetup 提供变量AppMutex,用来保存应用程序的Mutex名称.现在很多应用程序都是唯一实例运行.这样避免配置文件被错误修改以及其他很多衍 ...

  4. Oracle 11g 密码永不过期设置

    [原因/触发因素] 确定是由于oracle11g中默认在default概要文件中设置了“PASSWORD_LIFE_TIME=180天”所导致. [影响和风险] 影响 密码过期后,业务进程连接数据库异 ...

  5. bug_ _ _常见的bug??

    ======= 7    Failure [INSTALL_FAILED_INVALID_APK] 执行  adb install -r test.apk.时出现错误  Failure [INSTAL ...

  6. 动态作用域与this +apply和call +bind

    词法作用域是一套关于引擎如何寻找变量以及会在何处找到变量的规则. (函数作用域和块作用域) JavaScript 中的作用域就是词法作用域,也就是静态作用域,由定义代码决定 动态作用域似乎暗示有很好的 ...

  7. 序列最小最优化算法(SMO)-SVM的求解(续)

    在前一篇文章中,我们给出了感知器和逻辑回归的求解,还将SVM算法的求解推导到了最后一步,在这篇文章里面,我们将给出最后一步的求解.也就是我们接下来要介绍的序列最小最优化算法. 序列最小最优化算法(SM ...

  8. emacs配置eslint 语法检查.找不到node解决

    使用emacs配置eslint 当调用语法检查时报错 Suspicious state from syntax checker javascript-eslint: Checker javascrip ...

  9. Linux下创建新用户

    useradd -h查询使用方法 useradd -g sysadmin -d /home/devops -m -c "DevOps Installation User" -s / ...

  10. 【转载】变更MySql数据存储路径的方法

    1.在mysql安装目录下找到my.ini文件,更改#Path to the database root datadir="希望存放数据的地址" 2.将默认存放路径(一般为&quo ...