POJ-1068 Parencodings---模拟括号的配对
题目链接:
https://vjudge.net/problem/POJ-1068
题目大意:
给出一种括号序列的表示形式名叫P序列,规则是统计出每个右括号之前的左括号个数作为序列每项的值。然后要求你根据这个求括号列的W序列值,W序列的规则是统计每一个右括号和与其匹配的左括号之间所有匹配后的括号个数。
思路:
先模拟出括号序列,然后根据每个右括号向前入栈,记录中间的括号数目
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#define MEM(s, b) memset(a, b, sizeof(a));
using namespace std;
typedef long long ll;
int T, n, a[], b[], ans[];
int main()
{ cin >> T;
while(T--)
{
cin >> n;
string s;
MEM(a, );
MEM(b, );
MEM(ans, );
for(int i = ; i <= n; i++)cin >> a[i];
for(int i = ; i <= n; i++)
{
for(int j = ; j <= a[i] - a[i - ]; j++)s += '(';
s += ')';
}
// cout<<s<<endl;
int tot = ;
for(int i = ; i < s.size(); i++)
{
if(s[i] == ')')b[tot++] = i;
}
for(int i = ; i < tot; i++)
{
stack<char>q;
int cnt = ;
for(int j = b[i]; j >= ; j--)
{
if(s[j] == ')')q.push(s[j]);
else
{
q.pop();
cnt++;
if(q.empty())break;
}
}
ans[i] = cnt;
}
cout<<ans[];
for(int i = ; i < tot; i++)cout<<" "<<ans[i];
cout<<endl;
}
return ;
}
POJ-1068 Parencodings---模拟括号的配对的更多相关文章
- POJ 1068 Parencodings 模拟 难度:0
http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...
- [ACM] POJ 1068 Parencodings(模拟)
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19352 Accepted: 11675 De ...
- poj 1068 Parencodings 模拟题
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
- poj 1068 Parencodings 模拟
进入每个' ) '多少前' ( ', 我们力求在每' ) '多少前' ) ', 我的方法是最原始的图还原出来,去寻找')'. 用. . #include<stdio.h> #incl ...
- 模拟 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 (类似括号的处理问题)
Pare ...
- poj 1068 Parencodings(模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...
- poj 1068 Parencodings(栈)
题目链接:http://poj.org/problem?id=1068 思路分析:对栈的模拟,将栈中元素视为广义表,如 (((()()()))),可以看做 LS =< a1, a2..., a1 ...
- POJ 1068 Parencodings
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24932 Accepted: 14695 De ...
随机推荐
- V5.7_UTF8_SP1、SP2---任意前台用户登录(cookie伪造)
漏洞触发点在include/memberlogin.class.php中的MemberLogin类中的登录校验函数 可以看到M_ID参数是由GetNum(GetCookie("DedeUse ...
- S/4 HANA中的ACDOCT和FAGLFLEXT
最近的几个需求让我对ACDOCT和FAGLFLEXT这两个财务相关表(准确地说是视图)产生了一些了解,同时也发现某些开发同行和业务顾问并没有认识到这些东西.因此打算从技术角度来说明一下这两个视图在S4 ...
- 第一周CoreIDRAW课总结
一. 问:这节课学到了什么知识? 答:这节课我学到了很多知识,作为初学者的我,老师给我讲了CorelDEAW的启动,安装,基础知识和应用与用途. 基础知识 位图:是由无数个像素点构成的图像,又叫点 ...
- Angular-Mobile介绍
陆续更新中 1. 介绍: * Angular-Mobile是使用Angular和Bootstrap3为手机端网页和App提供支持的前端UI框架.
- weka实际操作--构建分类、回归模型
weka提供了几种处理数据的方式,其中分类和回归是平时用到最多的,也是非常容易理解的,分类就是在已有的数据基础上学习出一个分类函数或者构造出一个分类模型.这个函数或模型能够把数据集中地映射到某个给定的 ...
- WebGL 3D 工业隧道监控实战
前言 监控隧道内的车道堵塞情况.隧道内的车祸现场,在隧道中显示当前车祸位置并在隧道口给与提示等等功能都是非常有必要的.这个隧道 Demo 的主要内容包括:照明.风机.车道指示灯.交通信号灯.情报板.消 ...
- 兄弟连学Python-3Python变量和数据类型
变量:变量就是可以改变的量.如:x+y = 10 x=5 , y=? x=7 , y=? 这是数学里的变量 通俗的理解:变量 = 生活中的容器(盒子) 变量的赋值操作 = 我们把物品放 ...
- [poj2752]Seek the Name, Seek the Fame_KMP
Seek the Name, Seek the Fame poj-2752 题目大意:给出一个字符串p,求所有既是p的前缀又是p的后缀的所有字符串长度,由小到大输出. 注释:$1\le strlen( ...
- jmeter 前置处理器提取用户cookie信息 比如jsessionid
一般登录过程分成两步,一步是打开登录页面, 一步是输入用户名和密码登录 现在B/S架构的系统好多时候都只在客户端的cookie信息保留一个jsessionId,然后每次请求的时候在请求的头信息的coo ...
- css3控制div上下跳动-效果图
效果图演示,源代码