poj 1068 Parencodings(栈)
题目链接:http://poj.org/problem?id=1068
思路分析:对栈的模拟,将栈中元素视为广义表,如 (((()()()))),可以看做 LS =< a1, a2..., a12 >,对于可以配对的序列,如 <a4, a5>看做一个元素,其 W 值为1;
同理,<a6, a7>为一个元素,其W值为1,< a3, a4, a5, a6, a7, a8, a9, a10 >看做一个元素, 其W值为 <a4, a5> 与 <a6, a7>、< a8, a9 >的W的值的和加 1,即为4;
如此处理,直到求出所有的W值。
代码如下:
#include <iostream>
#include <stack>
using namespace std; int main()
{
int n;
char Record[]; // 广义表记录
stack<char> A; cin >> n;
for ( int i = ; i < n; ++i )
{
int Size, Index = -;
int Count1 = , Count2; cin >> Size;
for( int j = ; j < Size; ++j )
{
int W = , IsMatch = ; cin >> Count2;
for ( int k = ; k < Count2 - Count1; ++k )
A.push('('); while ( IsMatch == )
{
if ( A.top() == ')' )
{
A.pop();
W += Record[Index--];
}
else
{
A.pop();
IsMatch = ;
}
} A.push(')');
Record[++Index] = W;
Count1 = Count2; printf("%d ", W );
}
printf( "\n" );
} return ;
}
poj 1068 Parencodings(栈)的更多相关文章
- 模拟 POJ 1068 Parencodings
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...
- 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 (类似括号的处理问题)
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 ...
- poj 1068 Parencodings 模拟
进入每个' ) '多少前' ( ', 我们力求在每' ) '多少前' ) ', 我的方法是最原始的图还原出来,去寻找')'. 用. . #include<stdio.h> #incl ...
- poj 1068 Parencodings 模拟题
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
随机推荐
- Android进程的内存管理分析
尊重原创作者,转载请注明出处: http://blog.csdn.net/gemmem/article/details/8920039 最近在网上看了不少Android内存管理方面的博文,但是文章大多 ...
- jQuery validate api(转)
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...
- HTML静态网页(图片热点、网页划区、拼接及表单的使用)
图片热点: 规划出图片上的一个区域,可以做出超链接,直接点击图片区域就可以完成跳转的效果. 示例: 网页划区: 在一个网页里,规划出一个区域用来展示另一个网页的内容. 示例: 网页的拼接: 在一个 ...
- gsoap 超时(timeout)设置
参考:http://www.cs.fsu.edu/~engelen/soapdoc2.html#tth_sEc19.19 gsoap就不用介绍了,是一个c/c++编写的可用于服务端与客户端的连接工具. ...
- load和ready
<一>ready和load ready先执行,load后执行 DOM文档加载的步骤: () 解析HTML结构. () 加载外部脚本和样式表文件. () 解析并执行脚本代码. () 构造HT ...
- MYSQL事务和锁
mysql事务(一)—转载 2012年12月20日 ⁄ Mysql数据库, 技术交流 ⁄ 暂无评论 一. 什么是事务 事务就是一段sql 语句的批处理,但是这个批处理是一个atom(原子) ,不可分割 ...
- Python 城市菜单详解(超详解)
print("--------城市查询系统---------") print("--------按数值进行查询--------") menu={" ...
- (Problem 73)Counting fractions in a range
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...
- WebAppScaner
https://www.ohloh.net/p/simple-scan/ https://code.google.com/p/skipfish/ http://code.google.com/p/wa ...
- BZOJ 1002 轮状病毒 (基尔霍夫矩阵)
题解:http://vfleaking.blog.163.com/blog/static/17480763420119685112649/ #include <iostream> #inc ...