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 ...
随机推荐
- UNION 和 UNION ALL 区别
UNION用的比较多union all是直接连接,取到得是所有值,记录可能有重复 union 是取唯一值,记录没有重复 1.UNION 的语法如下: [SQL 语句 1] UNION [SQL 语句 ...
- Sqlite小数作差,会减不尽?
select 6307.65-5922.68 from CW_ZWMX 以上语句,在设Navigate中执行的结果是:384.969999999999 不解!!!
- 轻松进行iPad Safari设置
推荐 通过iPad Safari设置,iPad中的Safari可以让我们看到我们想看的影片.动画和Web应用程序,关闭部分内容以保护我们的隐私安全和设备安全,至于如何进行iPad Safari设置,下 ...
- oracle中找出某个字段中有非数字型的记录
工作中遇到一个大表记录中有非法非数字字符,不想用正则语法去做, 用一条SQL语句查出来的方法如下: select * from table where translate(col,'*01234567 ...
- [Maven]Maven详解
转自:http://www.cnblogs.com/hongwz/p/5456578.html 一.前言 以前做过的项目中,没有真正的使用过Maven,只知道其名声很大,其作用是用来管理jar ...
- html-tab page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 利用Oracle自带的impdp和expdp进行简单备份
目前有个这样的需求,每天晚上23点将生产库的数据备份到备份机器上,第二天备份机器的数据库可以直接使用,数据是昨天生产库的数据.(生产数据目前不多,全部数据不超过3000w条). 由于没有接触过高深的O ...
- sed字符串替换
把drivers目录下的所有pr_log替换成:pr_snd sed -i "s/pr_log/pr_snd/g" `grep pr_log -rl drivers/` 把driv ...
- ./upload/source/class/class_core.php
定义了core这个类 error_reporting(E_ALL); error_reporting() 设置 PHP 的报错级别并返回当前级别.可以参考手册. define('IN_DISCUZ', ...
- 一些常用的sql语句
1.查询表里的null值:is null 和 is not null select*from student where email is null 返回的该表里面邮箱为null的结果集 ...