poj1068 模拟
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 25010 | Accepted: 14745 |
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
Source
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
int n,t;
scanf("%d",&t);
while(t--)
{
int q1=,q2=;
string s;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d",&q1);
q2=q1-q2;
while(q2--)
s+="(";
s+=")";
q2=q1;
}
int num=s.size();
int cnt=;
for(int i=;i<num;i++)
{
if(s[i]==')')
{
cnt++;
int flag=;
int sum=;
for(int j=i-;j>=;j--)
{
if(flag==)
break;
if(s[j]=='(')
{
sum++;
flag-=;
}
else if(s[j]==')')
flag+=;
}
if(cnt!=n)
printf("%d ",sum);
else printf("%d\n",sum);
}
}
}
return ;
}
poj1068 模拟的更多相关文章
- [ACM_模拟] POJ1068 Parencodings (两种括号编码转化 规律 模拟)
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
- poj1068解题报告(模拟类)
POJ 1068,题目链接http://poj.org/problem?id=1068 题意: 对于给出给出的原括号串S,对应两种数字密码串P.W: S (((()()()))) P- ...
- [poj1068]Parencodings_模拟
Parencodings 题目大意:给你一个P序列,表示从左到右的右括号左边有多少左括号,求M序列. 注释:M序列定义为每一个右括号左边最近的没有被之前的右括号匹配的括号之间,有多少已经匹配的括号队对 ...
- POJ1068 Parencodings(模拟)
题目链接. 分析: 水题. #include <iostream> #include <cstdio> #include <cstring> using names ...
- POJ1068 --(模拟)
这题是在看一个书的时候的一个例题,当时并不明白啥意思,于是便找了下原题,以前没在POJ上刷过,这是开了个头,以后努力刷这个网站 题目大概意思是:http://poj.org/problem?id=10 ...
- poj1068 【模拟】
Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: ...
- POJ-1068 Parencodings---模拟括号的配对
题目链接: https://vjudge.net/problem/POJ-1068 题目大意: 给出一种括号序列的表示形式名叫P序列,规则是统计出每个右括号之前的左括号个数作为序列每项的值.然后要求你 ...
- App开发:模拟服务器数据接口 - MockApi
为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...
- 故障重现, JAVA进程内存不够时突然挂掉模拟
背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...
随机推荐
- pythonchallenge之C++学习篇-00
前言 最近学习下C++,之前是python的用户,python解释器有诸多实现,其中最出名的要数C实现了,而且很多python的扩展模块可能要用C或者C++来写的,所以很有必要学习下C++了 为了避免 ...
- CmRegisterCallback使用方法
部分代码 #include "my_sys_fun.h"#ifdef __cplusplusextern "C"{#endif //驱动加载函数 NTSTATU ...
- Arduino101学习笔记(二)—— 一些注意的语法点
1.宏定义 2.整数常量 3.支持C++ String类 (1)String 方法 charAt() compareTo() concat() endsWith() equals() equalsIg ...
- jq中.prop()与attr()的区别
一,定义 prop() 方法设置或返回被选元素的属性和值.prop() 方法应该用于检索属性值 attr() 方法设置或返回被选元素的属性和值.如需检索 HTML 属性,请使用 attr() 方法代 ...
- Uva10635 LCS
题目链接:http://vjudge.net/contest/137498#problem/G 题意:有两个长度为p+1和q+1的序列,每个序列的中的各个元素互不相同,且都是1~n^2之间的整.两个序 ...
- poj3642 01背包
http://poj.org/problem?id=3624 #include<iostream> #include<cstdio> #include<algorithm ...
- 系统表达式(z变换、DTFT、差分方程)之间的关系
- git学习 分支特殊处理和配置03
Bug分支: 当在一个分支上工作的时候:突然到其它分支修复bug,当前分支工作还没到要提交的程度:这时候可以使用git stash来将工作分支暂时存储起来: 用git stash list查看stas ...
- iOS instancetype or id ?
The id type simply says a method will return a reference to an object. It could be any object of any ...
- The 2015 China Collegiate Programming Contest K Game Rooms hdu 5550
Game Rooms Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...