Parencodings 分类: POJ 2015-06-28 22:00 7人阅读 评论(0) 收藏
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 22757 | Accepted: 13337 |
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
is the P-sequence of a well-formed 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#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <algorithm>
using namespace std; const int Max=1100000; int Arr[110];
bool vis[1100];
int main()
{
int T;
int n;
while(~scanf("%d",&T))
{
while(T--)
{
scanf("%d",&n);
int Max=0;
int sum;
for(int i=0;i<n;i++)
{
scanf("%d",&Arr[i]);
if(Arr[i]>Max)
{
Max=Arr[i];
}
}
Max+=n;
sum=Max;
memset(vis,false,sizeof(vis));
vis[Max]=true;
for(int i=n-2;i>=0;i--)
{ Max-=(Arr[i+1]-Arr[i]+1);
vis[Max]=true;
}
int top=0;
for(int i=1;i<=sum;i++)
{
if(vis[i])
{
int ans=0;
int ant=0;
for(int j=i;j>=1;j--)
{
if(vis[j])
{
ans++;
}
else
{
ans--;
ant++;
}
if(!ans)
{
break;
}
}
Arr[top++]=ant;
}
}
for(int i=0;i<n;i++)
{
if(i)
cout<<" ";
cout<<Arr[i];
}
cout<<endl;
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Parencodings 分类: POJ 2015-06-28 22:00 7人阅读 评论(0) 收藏的更多相关文章
- iOS正则表达式 分类: ios技术 2015-07-14 14:00 35人阅读 评论(0) 收藏
一.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...
- 全方位分析Objcetive-C Runtime 分类: ios技术 2015-03-11 22:29 77人阅读 评论(0) 收藏
本文详细整理了 Cocoa 的 Runtime 系统的知识,它使得 Objective-C 如虎添翼,具备了灵活的动态特性,使这门古老的语言焕发生机.主要内容如下: 引言 简介 与Runtime交互 ...
- C/C++文字常量与常变量的概念与区别 分类: C/C++ 2015-06-10 22:56 111人阅读 评论(0) 收藏
以下代码使用平台是Windows 64bits+VS2012. 在C/C++编程时,经常遇到以下几个概念:常量.文字常量.符号常量.字面常量.常变量.字符串常量和字符常量,网上博客资料也是千篇千律,不 ...
- 快速幂取模 分类: ACM TYPE 2014-08-29 22:01 95人阅读 评论(0) 收藏
#include<stdio.h> #include<stdlib.h> //快速幂算法,数论二分 long long powermod(int a,int b, int c) ...
- Hibernate检索方式 分类: SSH框架 2015-07-10 22:10 4人阅读 评论(0) 收藏
我们在项目应用中对数据进行最多的操作就是查询,数据的查询在所有ORM框架中也占有极其重要的地位.那么,如何利用Hibernate查询数据呢?Hibernate为我们提供了多种数据查询的方式,又称为Hi ...
- 由 argv引出的main参数 分类: C/C++ 2014-11-08 18:00 154人阅读 评论(0) 收藏
我们经常用的main函数都是不带参数的.因此main 后的括号都是空括号.实际上,main函数可以带参数,这个参数可以认为是 main函数的形式参数.C语言规定main函数的参数只能有两个, 习惯上这 ...
- Red and Black(BFS or DFS) 分类: dfs bfs 2015-07-05 22:52 2人阅读 评论(0) 收藏
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- IOS之富文本编辑 分类: ios技术 2015-03-06 22:51 89人阅读 评论(0) 收藏
之前做项目时遇到一个问题: 使用UITextView显示一段电影的简介,由于字数比较多,所以字体设置的很小,行间距和段间距也很小,一大段文字挤在一起看起来很别扭,想要把行间距调大,结 ...
- 【从0到1学Web前端】CSS伪类和伪元素 分类: HTML+CSS 2015-06-02 22:29 1065人阅读 评论(0) 收藏
1.CSS中的伪类 CSS 伪类用于向某些选择器添加特殊的效果. 语法: selector : pseudo-class {property: value} CSS 类也可与伪类搭配使用 select ...
随机推荐
- SpinLock 实现
/* Example: SpinLock Description: SpinLock is the lock implementation using AtomicInteger as a primi ...
- J2EE maven pom.xml常用的jar包
新建一个maven webapp工程,默认的pom.xml文件如下: <project xmlns="http://maven.apache.org/POM/4.0.0" x ...
- Topcoder SRM 598 div2
e,不知道为啥进不去了,这个B题贪心,从最小和最大的匹配如果超过了就只去最大的! 然后就没了- -! 这场比赛时不知为啥,string出问题了,可能是编译器挂了!0蛋- -!
- 最大权闭合图(Road constructions)hdu3917
题意:给出n个城市,k条道路,每条道路都有其负责的公司和花费,m个公司来投标修路,给出m个公司承包需要交纳的赋税,如果第i个公司负责修1-->2路,第j个公司负责修2-->3路,如果选择了 ...
- Python基础(1)python+Eclipse+pydev环境搭建
编辑器:Python 自带的 IDLE 简单快捷, 学习Python或者编写小型软件的时候.非常有用. 编辑器: Eclipse + pydev插件 1. Eclipse是写JAVA的 ...
- MyEclipse 下 Tomcat启动变慢如何解决
MyEclipse 下 Tomcat启动变慢如何解决 项目使用debug启动有时候会突然变得非常慢.不但启动慢,启动之后连打开项目页面也很慢,是日常的4,5倍.可以有下面的几种解决方法: 1. ...
- ViewPager相互嵌套,导致子ViewPager无法滑动,且子ViewPager中的view无法被点击
场景:当使用ViewPager进行嵌套的时候,子viewPager是无法进行嵌套的,因此我们要重写ViewPager类,并重写里层viewPager类中的onTouchEvent方法,调用其父 ...
- 夺命雷公狗---DEDECMS----16dedecms取出首页今日更新
我们这次就要来取出我们的电影和电视剧以及综艺节目: 我们首先在我们受页面的模版文件中获取电影和电视剧的标签: 我们发现这里有一大堆,我只留一个即可: 然后我们到后台更新下首页的模版,看下是否只有一个模 ...
- ThinkPHP讲解(七)——修改删除
修改数据 方式一:数组方式,直接将数据库里需要修改的内容进行修改 function Update() { //1.数组方式 $model=D("Info"); $attr=arra ...
- Sqlserver常用的时间函数---GETDATE、GETUTCDATE、DATENAME
GETDATE 按 datetime 值的 Microsoft® SQL Server™ 标准内部格式返回当前系统日期和时间.语法GETDATE ( )返回类型datetime注释日期函数可用在 SE ...