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 ...
随机推荐
- 数据库性能之--ibatis cache应用
(1)利用cache是提升性能的一个很重要方式!cacheModel节点定义了本映射文件中使用的Cache机制:<cacheModel id="userCache" type ...
- 资源Createwindow,对应标识符,绑定窗口
问? 定义一个CEdit cedit1:怎么和IDC_EDIT1 关联,可以在CEdit.Create()里传进去或者在DoDataExchange()里面绑定,是不是一定要先弄出个IDC_EDIT1 ...
- 强连通(hdu4635)最多增加几条单向边后满足最终的图形不是强连通
Strongly connected Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- ruby初步学习中遇到的错误
print <<off This is the second way of creating here document ie. multiple line string; off 报错: ...
- Android测试AsyncTask下载图片
package com.example.myact8_async; import org.apache.http.HttpEntity; import org.apache.http.HttpResp ...
- Oracle中的MD5加密
一.技术点 1. DBMS_OBFUSCATION_TOOLKIT.MD5 DBMS_OBFUSCATION_TOOLKIT.MD5是MD5编码的数据包函数,但偶在使用select DBMS_OBFU ...
- 夺命雷公狗jquery---5可见选择器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- [Ubuntu] Linux下使用google app engine,无法打开https网站的解决方法
为什么这里写的是 google app engine?原因我就不解释了.步骤如下: 1)安装证书导入工具:$ sudo apt-get install libnss3-tools 2)导入CA.crt ...
- [php] PHPStorm8 for Yincart project
PHPStorm8 license for Yincart project: https://github.com/yinheark/yincart2 User Name: Yincart ===== ...
- Qt源码包中的一段代码
之所以单独拣出来是因为Qt的开发者们给普通开发者提供了高效编程的商业代码例子: bool QWidget::testAttribute_helper(Qt::WidgetAttribute attri ...