poj1068
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 18785 | Accepted: 11320 |
Description
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
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
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的更多相关文章
- [POJ1068]Parencodings
[POJ1068]Parencodings 试题描述 Let S = s1 s2...s2n be a well-formed string of parentheses. S can be enco ...
- POJ-1068 Parencodings---模拟括号的配对
题目链接: https://vjudge.net/problem/POJ-1068 题目大意: 给出一种括号序列的表示形式名叫P序列,规则是统计出每个右括号之前的左括号个数作为序列每项的值.然后要求你 ...
- POJ-1068题
下面的代码是北京大学Online Judge网站上1068题(网址:http://poj.org/problem?id=1068)的所写的代码. 该题的难点在于实现括号匹配,我在代码中采取用-1和1分 ...
- [ACM_模拟] POJ1068 Parencodings (两种括号编码转化 规律 模拟)
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
- NUC_HomeWork1 -- POJ1068
A - Parencodings Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Su ...
- poj1068 模拟
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25010 Accepted: 14745 De ...
- poj1068解题报告(模拟类)
POJ 1068,题目链接http://poj.org/problem?id=1068 题意: 对于给出给出的原括号串S,对应两种数字密码串P.W: S (((()()()))) P- ...
- POJ1068——Parencodings
Parencodings Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encode ...
- POJ1068 Parencodings(模拟)
题目链接. 分析: 水题. #include <iostream> #include <cstdio> #include <cstring> using names ...
随机推荐
- SQLite常用语句
// 错误存储路径 - (NSString *)dataFilePath{ NSString *dbPath = [NSSearchPathForDirectoriesInDomains(NSLibr ...
- Linux命令(23)grep命令的使用
grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正 ...
- Redis内存使用优化与存储
抄自http://www.infoq.com/cn/articles/tq-redis-memory-usage-optimization-storage 本文将对Redis的常见数据类型的使用场景以 ...
- [手机取证] Apple Watch取证初探
转载文章请注明出处 1. 关于Apple Watch 苹果公司在2015年3月正式发布了智能手表Apple Watch,包括Apple Watch.Apple Watch Sport以及Apple W ...
- MYSQL PERFORMANCE_SCHEMA HINTS
ACCOUNTS NOT PROPERLY CLOSING CONNECTIONS [ 1 ] Works since 5.6 SELECT ess.user, ess.host , (a.total ...
- Hive On Spark hiveserver2方式使用
启动hiveserver2: hiveserver2 --hiveconf hive.execution.engine=spark spark.master=yarn 使用beeline连接hives ...
- 细说IIS异常日志 — 你必须知道的功能
最近在跟QAD用Webservice搞接口做数据维护,搞的哥那个叫头大,遇到很多问题,系统的log4net根本就无法记录.话说QAD调我某一个接口,可能包含几百个字段,而且QAD是个产品,所以我这边提 ...
- Dynamics AX Hostory
现在谈起Dynamics AX,在微软Dynamics系列产品当中,作为最受瞩目和最有前景的Dynamics套装产品线,很多人也许只知道它曾经由于资本市场的上市和并购,前后经历了三个“东家”.对于它长 ...
- JAVA IO 学习
Java流的分类 1.输入/输出流 输入流:只能向其读数据,不能写. 输出流:只能向其写数据,不能读. 所谓的输入输出都是相对应用程序而言的. 2.字节流/字符流 单位不同,字节流操作8位,字符流操作 ...
- webstrom11 和12破解码
很多人都发现 http://idea.lanyus.com/ 不能激活了 很多帖子说的 http://15.idea.lanyus.com/ 之类都用不了了,最近封的厉害仅作测试. 红色字体的是最近大 ...