题目地址:http://poj.org/problem?id=1068

 /*
题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列)
模拟题:无算法,s数组把左括号记为-1,右括号记为1,然后对于每个右括号,numl记录之前的左括号
numr记录之前的右括号,sum累加s[i]的值,当sum == 0,并且s[i]是左括号(一对括号)结束,记录b[]记录numl的值即为答案
我当时题目没读懂,浪费很长时间。另外,可以用vector存储括号,还原字符串本来的样子
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
using namespace std; const int MAXN = + ;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int b[MAXN];
int s[]; void work(int n)
{
memset (s, , sizeof (s)); int k = a[];
for (int i=; i<=k; ++i) s[i] = -;
s[++k] = ; int cnt;
for (int i=; i<=n; ++i)
{
cnt = a[i] - a[i-];
for (int j=k+; j<=k++cnt; ++j)
{
s[j] = -;
}
k += cnt;
s[++k] = ;
}
int t = ;
for (int i=; i<=k; ++i)
{
if (s[i] == )
{
int sum = s[i];
int numl = , numr = ;
for (int j=i-; j>=; --j)
{
if (s[j] == ) numr++;
else numl++;
sum += s[j];
if (sum == )
{
b[++t] = numl; break;
}
}
}
}
int first = ;
for (int i=; i<=t; ++i)
{
if (first)
{
cout << b[i]; first = ;
}
else cout << " " << b[i];
}
cout << endl;
} int main(void) //POJ 1068 Parencodings
{
//freopen ("F.in", "r", stdin); int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i=; i<=n; ++i) cin >> a[i]; work (n);
} return ;
}

模拟 POJ 1068 Parencodings的更多相关文章

  1. POJ 1068 Parencodings【水模拟--数括号】

    链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...

  2. POJ 1068 Parencodings 模拟 难度:0

    http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...

  3. poj 1068 Parencodings(模拟)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...

  4. [ACM] POJ 1068 Parencodings(模拟)

    Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19352   Accepted: 11675 De ...

  5. poj 1068 Parencodings 模拟

    进入每个' )  '多少前' (  ', 我们力求在每' ) '多少前' )  ', 我的方法是最原始的图还原出来,去寻找')'. 用. . #include<stdio.h> #incl ...

  6. poj 1068 Parencodings 模拟题

    Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...

  7. poj 1068 Parencodings(栈)

    题目链接:http://poj.org/problem?id=1068 思路分析:对栈的模拟,将栈中元素视为广义表,如 (((()()()))),可以看做 LS =< a1, a2..., a1 ...

  8. POJ 1068 Parencodings (类似括号的处理问题)

                                                                                                    Pare ...

  9. POJ 1068 Parencodings

    Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24932   Accepted: 14695 De ...

随机推荐

  1. 教你安装漂亮的Arc GTK主题

    导读 近日,我们又发现了一款深受 Linux 用户喜爱的桌面主题 — Arc GTK,Arc GTK 主题已被很多 GNU/Linux 操作系统支持和采用,其中就包括即将到来的 Linux Mint ...

  2. 暑假热身 A. GCC

    GCC编译器是一个由GNU项目维护的编译系统,它支持多种编程语言的编译.但是它并不包含数学运算符“!”.在数学中,这个符号代表阶乘.表达式n!的意思是从1到n的所有整数的乘积. 例如,4!=4*3*2 ...

  3. django-cms 代码研究(二)bugs?

    djangocms集成到现有项目中后,发现了几个问题: 1. 现有项目的url匹配失效,下面requests请求被交给djangocms处理了 url(r'^admin/', include(admi ...

  4. malloc/free vs new/delete

    malloc/new是库函数. new/delete是运算符. 对于非内部数据类型的对象而言,光用malloc/free 无法满足动态对象的要求.对象在创建的同时要自动执行构造函数, 对象在消亡之前要 ...

  5. Bootstrap分页插件:bootstrap-paginator

    今天和大家分享一个Bootstrap的分页插件:bootstrap-paginator. 插件地址: https://github.com/lyonlai/bootstrap-paginator 先看 ...

  6. UVALive 7269 Snake Carpet (构造)

    题目:传送门. 题意:构造出一个矩阵,使得矩阵含有n条蛇,每条蛇的长度是1到n,并且奇数长度的蛇有奇数个拐弯,偶数长度 的蛇有偶数个拐弯. 奇数和偶数分开构造,奇数可以是: 1357 3357 555 ...

  7. [SVN(Ubuntu)] SVN 查看历史详细信息

    转载: http://lee2013.iteye.com/blog/1074457 以下内容,对ubuntu命令行查看代码变化非常有用. SVN 查看历史信息 通过svn命令可以根据时间或修订号去除过 ...

  8. Hibernate常见问题

    问题1,hql条件查询报错 执行Query session.createQuery(hql) 报错误直接跳到finally 解决方案 加入 <prop key="hibernate.q ...

  9. Ant基本使用指南

    近期碰到了其他人在讨论这个ant,已经很多人在使用,故对他进行收集资料进了解,以便方便去使用.同时,在学习struts+spring+hibernate,尤其是Appfuse的过程中大量涉及到ant的 ...

  10. error: Refusing to undefine while domain managed save image exists

    [root@ok libvirt]# virsh undefine win7 error: Refusing to undefine while domain managed save image e ...