Hdu1361&&Poj1068 Parencodings 2017-01-18 17:17 45人阅读 评论(0) 收藏
Parencodings
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 5 Accepted Submission(s) : 5
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
- 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).
- 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
string. It contains n positive integers, separated with blanks, representing the P-sequence.
Output
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
Source
—————————————————————————————————————————————————
题意:
有两个规则:
1、p序列表示一个括号字符串的每一个右括号的前面有多少个左括号;
2、w序列表示一个括号字符串的每一个右括号在和自己匹配的左括号之间(包括自己这一对)有多少了完整的括号;
现在给出p序列求w序列;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
int P[50];
int W[50];
int a[50];
int main()
{
int T;
int n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&P[i]);
a[0]=P[1];
for(int i=1;i<n;i++)
a[i]=P[i+1]-P[i];
int j;
for(int i=1;i<=n;i++)
{
for(j=i-1;j>=0;j--)
{
if(a[j]>0)
{
a[j]--;
break;
}
}
W[i]=i-j;
}
for(int i=1;i<n;i++)
printf("%d ",W[i]);
printf("%d\n",W[n]);
}
return 0;
}
Hdu1361&&Poj1068 Parencodings 2017-01-18 17:17 45人阅读 评论(0) 收藏的更多相关文章
- Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏
在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...
- APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏
APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...
- Hdu428 漫步校园 2017-01-18 17:43 88人阅读 评论(0) 收藏
漫步校园 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
- The 3n + 1 problem 分类: POJ 2015-06-12 17:50 11人阅读 评论(0) 收藏
The 3n + 1 problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53927 Accepted: 17 ...
- POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 5791 ...
- 多校4-Walk Out 分类: 比赛 2015-08-02 17:15 21人阅读 评论(0) 收藏
Walk Out Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Subm ...
- strace使用详解(转) 分类: shell ubuntu 2014-11-27 17:48 134人阅读 评论(0) 收藏
(一) strace 命令 用途:打印 STREAMS 跟踪消息. 语法:strace [ mid sid level ] ... 描述:没有参数的 strace 命令将所有的驱动程序和模块中的 ...
- 转自知乎,亲民好酒推荐 分类: fool_tree的笔记本 2014-11-08 17:37 652人阅读 评论(0) 收藏
这里尽量为大家推荐一些符合大众喜好.业内公认好评."即使你不喜欢,你也会承认它不错"的酒款.而且介绍到的酒款还会有一个共同的特征,就是能让你方便的在网上买到. 大概会分为烈酒,利口 ...
- Cubieboard 开箱和入门 | Name5566 分类: cubieboard 2014-11-08 17:27 251人阅读 评论(0) 收藏
Cubieboard 开箱和入门 2014 年 01 月 29 日 by name5566 Categories: Computer Science, Cubieboard Hello Cubiebo ...
随机推荐
- cprogram作业
刘金福 SA17225205 第三次作业 url:http://blog.csdn.net/liu896749150/article/details/78176433 学号:SA17225404 姓名 ...
- frame标签使用
今天在做onebyone作业的时候,为了使自己的页面更加美观,我便使用了frame框架,百度了他的用法,总结如下 frame,是网页开发必须掌握的知识.例如后台架构.局部刷新,页面分割,都是frame ...
- MySQL 事务 是对数据进行操作,对结构没有影响,比如创建表、删除表,事务就不起作用
- mysql 中文编码问题
- 第八章 高级搜索树 (xa4)红黑树:删除
- 115. Distinct Subsequences (String; DP)
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- ssh登录忽略known_hosts列表
编辑 ~/.ssh/config 如果不存在,可以先创建,并且要注意其读写权限 mkdir -p ~/.ssh touch ~/.ssh/config ~/.ssh/config 文件内容如下 Log ...
- 分析maven的优点
1.依赖管理: 就是对jar包的管理. 2.项目的一键构建: 编译--->测试--->运行--->打包--->安装 运行一个maven工程(web工程)只需要一个命令:toma ...
- install package
http://www.michael-noll.com/blog/2014/03/17/wirbelsturm-one-click-deploy-storm-kafka-clusters-with-v ...
- svn.SvnX
1. 使用SvnX的入门 http://www.divvun.no/doc/tools/docu-svn-user-svnx.html 2. SvnX的代码 https://code.google.c ...