Parencodings - poj 1068
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 22764 | Accepted: 13344 |
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
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
这道题很简单,一遍AC,用flag数组记录左括号的状态,当是1时已经匹配,当是0时未匹配,向前查找第一个未匹配的左括号,记录中间匹配的左括号的个数
#include <iostream>
using namespace std; int main() {
int num;
int n;
int p[];
int flag[];
cin>>num;
for(int i=;i<num;i++){
cin>>n;
for(int j=;j<n;j++){
cin>>p[j];
flag[j]=;
}
for(int k=;k<n;k++){
int count=;
for(int m=p[k]-;m>=;m--){
if(flag[m]==){
cout<<count+<<" ";
flag[m]=;
break;
}else{
count++;
}
}
}
cout<<endl;
}
return ;
}
Parencodings - poj 1068的更多相关文章
- 模拟 POJ 1068 Parencodings
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...
- poj 1068 模拟
题目链接 大概题意就是告诉你有个n个小括号,每一个")"左边有多少个"("都告诉你了,然后让你求出每一对括号之间有多少对括号(包含自己本身). 思路: 我先计算 ...
- POJ 1068 Parencodings【水模拟--数括号】
链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...
- POJ 1068 Parencodings 模拟 难度:0
http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...
- poj 1068 Parencodings(栈)
题目链接:http://poj.org/problem?id=1068 思路分析:对栈的模拟,将栈中元素视为广义表,如 (((()()()))),可以看做 LS =< a1, a2..., a1 ...
- POJ 1068 Parencodings (类似括号的处理问题)
Pare ...
- poj 1068 Parencodings(模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...
- POJ 1068 Parencodings
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24932 Accepted: 14695 De ...
- [ACM] POJ 1068 Parencodings(模拟)
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19352 Accepted: 11675 De ...
随机推荐
- HashSet、LinkedHashSet和TreeSet
关键技术: HashSet采用散列函数对元素进行排序,是专门为快速查询而设计的.存入HashSet的对象必须定义hashCode方法. TreeSet采用红黑树的数据结构进行排序元素,使用它可以从Se ...
- 可持久化线段树(主席树)(图文并茂详解)【poj2104】【区间第k大】
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=63740442 向大(hei)佬(e)实力学(di ...
- 【面试题】2018年最全Java面试通关秘籍 四套!(无答案)
http://mp.weixin.qq.com/s/RQMQUufCbwlkAK62y57DAw 第一套:<2018年最全Java面试通关秘籍第一套!> 第二套:<2018年最全Ja ...
- hdu 5206 Four Inages Strategy 计算几何
题目链接:HDU - 5206 Young F found a secret record which inherited from ancient times in ancestral home b ...
- sqlsever 和oracle的参数
StringBuilder strSql = new StringBuilder(); strSql.Append("insert into YXZY_TSDQWH("); str ...
- Android开发之如何保证Service不被杀掉(broadcast+system/app
Android开发之如何保证Service不被杀掉(broadcast+system/app) 序言 最近项目要实现这样一个效果:运行后,要有一个service始终保持在后台运行,不管用户作出什么操作 ...
- Bluetooth篇 开发实例之九 和蓝牙模块通信
首先,我们要去连接蓝牙模块,那么,我们只要写客户端的程序就好了,蓝牙模块就相当于服务端. 连接就需要UUID. #蓝牙串口服务SerialPortServiceClass_UUID = ‘{00001 ...
- Matlab中ismember用法
>> a = magic(3) a = 8 1 6 3 5 7 4 9 2 >> ismember(a,3) ans = 0 0 0 1 0 0 0 0 0 >> ...
- 墨卡托投影、高斯-克吕格投影、UTM投影及我国分带方法
转自原文 墨卡托投影.高斯-克吕格投影.UTM投影及我国分带方法 一.墨卡托投影.高斯-克吕格投影.UTM投影 1. 墨卡托(Mercator)投影 墨卡托(Mercator)投影,是一种" ...
- docker运行mysql
http://blog.csdn.net/u011492260/article/details/77970445 第一步: 安装Docker:首先到docker官网下载适合自己电脑当前系统的版本,并安 ...