模拟 POJ 1068 Parencodings
题目地址: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的更多相关文章
- 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(模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...
- [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 ...
- poj 1068 Parencodings(栈)
题目链接:http://poj.org/problem?id=1068 思路分析:对栈的模拟,将栈中元素视为广义表,如 (((()()()))),可以看做 LS =< a1, a2..., a1 ...
- POJ 1068 Parencodings (类似括号的处理问题)
Pare ...
- POJ 1068 Parencodings
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24932 Accepted: 14695 De ...
随机推荐
- Power of Cryptography(用double的泰勒公式可行分析)
Power of Cryptography Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...
- Linux解压安装与卸载
linux tar.gz zip 解压缩 压缩命令 linux下安装软件主要有这么几种: 1.自动安装: yum install package 2.用二进制文件安装:rpm -ivh file.rp ...
- iOS文件存储路径规定
Storing Your App’s Data Efficiently https://developer.apple.com/icloud/documentation/data-storage/in ...
- Vmware怎样使用nat和桥接方式解决虚拟机联网问题
对于很多的linux初学者来说,最开始学习linux时通常是在虚拟机上进行的,然而对于新手来说虚拟机联网会对他们来说是比较困难的.这里我根据自己的经验写了一篇文档分享给大家.下面对几种连接方式进行简单 ...
- c++ exports def文件
https://msdn.microsoft.com/zh-cn/library/hyx1zcd3(v=vs.80).aspx EXPORTS 引入了一个由一个或多个 definitions(导出的函 ...
- ubuntu 12.04 server编译安装nginx
tar -xvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./config make make install above is for zlib(refers http:// ...
- Nginx图片剪裁模块探究 http_image_filter_module
官方地址:http://nginx.org/en/docs/http/ngx_http_image_filter_module.html 煮酒品茶:前半部安装和官方说明,后半部分实践 #yum ins ...
- jstack命令详解
jstack用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息,如果是在64位机器上,需要指定选项"-J-d64",Windows的jstack使 ...
- PeopleEditor允许客户端输入的同时验证输入的内容
如何判断PeopleEditor的值为空 在sharepoint开发中,我们经常会用到PeopleEditor这一控件,最近我在写程序的时候用到了,开始的时候不知道怎么用,后来问题解决啦,现在写出 ...
- 2013 ACM/ICPC 长春网络赛F题
题意:两个人轮流说数字,第一个人可以说区间[1~k]中的一个,之后每次每人都可以说一个比前一个人所说数字大一点的数字,相邻两次数字只差在区间[1~k].谁先>=N,谁输.问最后是第一个人赢还是第 ...