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. Hibernate5.2之一对一外键关联(五)

                                                     Hibernate5.2之一对一外键关联(五) 一.简介 上篇文章中笔者介绍了Hibernate关联关 ...

  2. ctype.h库函数----字符操作函数

    在c++中使用时:  #include <cctype> 字符判断函数 1.isalnum函数--判断是否是英文字母或数字字符,如果是,则返回非0值,如果不是,则返回0. 函数参数 :可以 ...

  3. Linux使用ssh公钥实现免密码登录Linux

    ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例.有机器A(192.168.1.155),B(192.168.1.181).现想A ...

  4. 01-C#入门(函数重载、委托)

    函数的重载 相对委托,是比较好理解的. 涉及一个概念:函数签名.函数签名包括函数的名称和参数,而函数重载:就是使用相同的名称和不同的参数(参数类型.传递方式[传值或引用])来实现的.而不能声明相同的函 ...

  5. Esfog_UnityShader教程_遮挡描边(实现篇)

     在上一篇中,我们基本上说明了遮挡描边实现的一种基本原理.这一篇中我们将了解一下基于这种原理的具体实现代码.本篇中的内容和前几篇教程相比,相对比较难一些,建议先有一些基本的Unity的C#脚本编程经验 ...

  6. Ejabberd 插件开发 --- IQ截获与处理

    ejabberd的组件开发其实是非常简单的,只要遵循其gen_mod规范,添加iq处理函数就可以了.下面一步步教大家如何开发ejabberd组件. 首先,最好是自己编译ejabberd源码,这样的话把 ...

  7. 初级Bug率,随时受不了

    一听到初级Bug这个名字,很多开发工程师都会觉得很头痛,还有那个“初级Bug率”,让人随时受不了. 初级Bug这个概念,在多数缺陷跟踪工具中,是不存在的,可以说是淘宝研发部的特色.初级Bug对应Bug ...

  8. Struts2中使用OGNL

    链接:Struts标签库 OGNL(Object Graphic Navigatino Language) OGNL称为对象图导航语言.以一个对象为根(起点),通过OGNL可以访问与这个对象关联的其它 ...

  9. C# Socket简单例子(服务器与客户端通信)

    这个例子只是简单实现了如何使用 Socket 类实现面向连接的通信. 注意:此例子的目的只是为了说明用套接字写程序的大概思路,而不是实际项目中的使用程序.在这个例子中,实际上还有很多问题没有解决,如消 ...

  10. 在Mac上配置adb命令

    在Mac上配置adb命令 在Mac OS中使用adb命令时,应进行变量配置,步骤如下: 一.终端中输入 cd ~ 二.输入touch .bash_profile 回车 touch:如果没有,则创建文件 ...