Parencodings(imitate)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 20679 | Accepted: 12436 |
Description
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
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
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int p[] , w[] ;
int n ;
char s[] ; void convert1 ()
{
int k = ;
for (int i = ; i < p[] ; i++)
s[k++] = '(' ;
s[k++] = ')' ;
for (int i = ; i < n ; i++) {
for (int j = ; j < p[i] - p[i - ]; j++) {
s[k++] = '(' ;
}
s[k++] = ')' ;
}
s[k] = '\0' ;
// puts (s) ;
}
void convert2 ()
{
int l , r ;
int k = ;
for (int i = ; s[i] != '\0' ; i++) {
if (s[i] == ')') {
l = ;
r = ;
for (int j = i - ; j >= ; j--) {
if (s[j] == ')' )
r++ ;
else
l++ ;
if (l == r)
break ;
}
w[k++] = r;
}
}
for (int i = ; i < n ; i++) {
printf ("%d" , w[i]) ;
if (i != n - )
printf (" ") ;
}
puts ("") ;
}
int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
int T ;
scanf ("%d" , &T) ;
while (T--) {
scanf ("%d" , &n) ;
for (int i = ; i < n ; i++)
scanf ("%d" , &p[i]) ;
convert1 () ;
convert2 () ;
}
}
Parencodings(imitate)的更多相关文章
- [POJ1068]Parencodings
[POJ1068]Parencodings 试题描述 Let S = s1 s2...s2n be a well-formed string of parentheses. S can be enco ...
- 模拟 POJ 1068 Parencodings
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...
- Parencodings 分类: POJ 2015-06-28 22:00 7人阅读 评论(0) 收藏
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22757 Accepted: 13337 De ...
- hdu 1361 Parencodings 简单模拟
Parencodings 题意: 由括号序列S可经P规则和W规则变形为P序列和W序列. p规则是:pi是第i个右括号左边的左括号的数: w规则是:wi是第i右括号与它匹配的左括号之间右括号的数(其中包 ...
- POJ 1068 Parencodings
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24932 Accepted: 14695 De ...
- Poj OpenJudge 1068 Parencodings
1.Link: http://poj.org/problem?id=1068 http://bailian.openjudge.cn/practice/1068 2.Content: Parencod ...
- POJ1068——Parencodings
Parencodings Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encode ...
- PO1068 Parencodings 模拟题
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28860 Accepted: 16997 De ...
- Hdu1361&&Poj1068 Parencodings 2017-01-18 17:17 45人阅读 评论(0) 收藏
Parencodings Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
随机推荐
- MVC5 + EF6 + Bootstrap3 (10) 数据查询页面
文章来源:Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc5-ef6-bs3-get-started-search-page.html 系列教程:MVC ...
- 远程办公《Remote》读书笔记:中国程序员在家上班月入过六万不是梦
这不是一本新书,这是一本很值得中国程序员看的老书,所以我不是来做卖新书广告的:) 但它的确是一本好书,这本书在Amazon上3个business categories排第一.作者Jason Fried ...
- 扫描函数sweep
groot.sweep(element,vm); element 为要扫描的代码片段,vm 对应的一个 groot.view 定义的 一个Vm的整体 扫面代码 groot.sweep = functi ...
- [USACO2005][POJ2454]Jersey Politics(随机化)
题目:http://poj.org/problem?id=2454 题意:给你3*k(k<=60)个数,你要将它们分成3个长度为k的序列,使得其中至少有两个序列的和大于k*500 分析:以为有高 ...
- 第四十课:CSS3 transition详解
W3C中对transition是这样描述的:允许css的属性值在一定的时间内平滑的过渡,也就是说,以动画的效果改变css的属性值. transition主要包含4个属性值:transition-pro ...
- Oracle数据库sys为什么只能以sysdba登录
1.我们都知道,Oracle有两个具有dba角色的用户,分别是sys与system,他们都可以以sysdba身份登录数据库.既然system具有dba角色,为什么还分配他sysoper身份? [sys ...
- iOS7(iPhone4)button不能改变button的title
最近整了个高端的iPhone4测试机,系统是iOS7.1,测出一个问题,两个button,第二个的enable为NO,点击第一个button,第二个的title改变,然而在iPhone4上并不能运行, ...
- Cocos2d-X3.0 刨根问底(九)----- 场景切换(TransitionScene)源码分析
上一章我们分析了Scene与Layer相关类的源码,对Cocos2d-x的场景有了初步了解,这章我们来分析一下场景变换TransitionScene源码. 直接看TransitionScene的定义 ...
- hdu1695 莫比乌斯反演
莫比乌斯反演:可参考论文:<POI XIV Stage.1 <Queries>解题报告By Kwc-Oliver> 求莫比乌斯函数mu[i]:(kuangbin模板) http ...
- POJ2392Space Elevator(贪心+背包)
Space Elevator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9970 Accepted: 4738 De ...