Poj_1068 Parencodings】的更多相关文章

S     (((( )( )() ) ) ) P-sequence     4 5 6666,表示第i个右括号的左边有几个左括号. W-sequence    1 1 1456,表示第i个右括号和以它为起点的序列中的第几个左括号配对. 问题:已知P序列求W序列. 解决:用字符串数组存放括号序列,再通过遍历和多个标号的出W序列.先找到第一个右括号,在遍历它的左边的括号序列,如果为左括号,则原来为1的标号indexz自减,用于计数的sum自加.如果为右括号则index自加.并每次都判断sum的值,…
[POJ1068]Parencodings 试题描述 Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: 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…
Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20679   Accepted: 12436 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:  q By an integer sequence P = p1 p2...pn…
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左括号记为-1,右括号记为1,然后对于每个右括号,numl记录之前的左括号 numr记录之前的右括号,sum累加s[i]的值,当sum == 0,并且s[i]是左括号(一对括号)结束,记录b[]记录numl的值即为答案 我当时题目没读懂,浪费很长时间.另外,可以用vector存储括号,还原字符串本来的…
Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22757   Accepted: 13337 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2...pn…
Parencodings 题意: 由括号序列S可经P规则和W规则变形为P序列和W序列. p规则是:pi是第i个右括号左边的左括号的数: w规则是:wi是第i右括号与它匹配的左括号之间右括号的数(其中包括它本身). 题解: 这题真的好简单,数据也小,算是一个增加了我信心的题吧. 1是左括号,2是右括号. 代码: #include <vector> #include <cstdio> #include <string> #include <cstdlib> #i…
Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24932   Accepted: 14695 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2...pn…
1.Link: http://poj.org/problem?id=1068 http://bailian.openjudge.cn/practice/1068 2.Content: Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20077   Accepted: 12122 Description Let S = s1 s2...s2n be a well-formed string of p…
Parencodings Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: 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-s…
Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28860   Accepted: 16997 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2...pn…
Parencodings Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 5   Accepted Submission(s) : 5 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Let S = s1 s2 - s2n be a w…
ZOJ Problem Set - 1016 Parencodings Time Limit: 2 Seconds      Memory Limit: 65536 KB Let S = s1 s2 ... s2n be a well-formed string of parentheses. S can be encoded in two different ways: By an integer sequence P = p1 p2 ... pn where pi is the number…
[poj1068] Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26686   Accepted: 15645 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p…
链接: http://poj.org/problem?id=1068 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#problem/B Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17044   Accepted: 10199 Description Let S = s1 s2...s2n be a well-forme…
                                                                                                Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19550   Accepted: 11804 Description Let S = s1 s2...s2n be a well-formed string…
Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19352   Accepted: 11675 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:  q By an integer sequence P = p1 p2...pn…
Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22849   Accepted: 13394 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:  q By an integer sequence P = p1 p2...pn…
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: 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 B…
http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; int ind[45]; bool used[45]; int r[21]; int l[21]; int len,n,llen; int w[21]; int main(){ int t; scanf("%d",&t); while(t--){ memset(used,0,siz…
原题链接 题目大意:有两串数字P和W.数组P中,数字P[i]表示第i个右括号之前的左括号个数.数组W中,数字W[i]表示在第i个右括号和与它匹配的左括号之间的右括号的个数(包括本身).给出一个数组P,求对应的数组W. 解法:开辟一个和括号对数相同大小的数组flag[],初始化0.从P数组读入一个数字a,若flag[a]不等于0,说明对应的左括号已经被用了,继续往前查找,直到找到第一个0.两个元素的下标之差+1就是他们间隔的右括号个数. 参考代码: #include<iostream> #inc…
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: 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 B…
题目链接. 分析: 水题. #include <iostream> #include <cstdio> #include <cstring> using namespace std; ; int P[maxn], W[maxn]; char s[maxn]; int main(){ int T, n, m; scanf("%d", &T); while(T--) { scanf("%d", &n); P[] = ;…
题目链接: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…
进入每个' )  '多少前' (  ', 我们力求在每' ) '多少前' )  ', 我的方法是最原始的图还原出来,去寻找')'. 用. . #include<stdio.h> #include<string.h> int y[505],t[505]; char s[505]; int main() { int a,b,i,j,u; scanf("%d",&a); while(a--) { memset(y,0,sizeof(y)); memset(t,…
题目链接 Problem Description Let S = s1 s2 … s2n be a well-formed string of parentheses. S can be encoded in two different ways: By an integer sequence P = p1 p2 … pn where pi is the number of left parentheses before the ith right parenthesis in S (P-seq…
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: 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 B…
  Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22764   Accepted: 13344 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2...pn where pi is…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1361 题目意思: 根据输入的P-sequence , 输出对应的W-sequence.   P-sequence: 表示每个右括号前有多少个左括号;   W-sequence: 表示每个右括号要经过多少个左括号才能找到它能够匹配的左括号. 可以通过栈来做,边输入边处理.假设左括号用-1表示, 已经匹配好的括号(即 () ) 用1表示.那么,如果是左括号的话,就把-1压进去.直到找到匹配的括号. 以…
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: 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 B…
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem? id=1068 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:  q By an integer sequ…