POJ 1068】的更多相关文章

题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左括号记为-1,右括号记为1,然后对于每个右括号,numl记录之前的左括号 numr记录之前的右括号,sum累加s[i]的值,当sum == 0,并且s[i]是左括号(一对括号)结束,记录b[]记录numl的值即为答案 我当时题目没读懂,浪费很长时间.另外,可以用vector存储括号,还原字符串本来的…
题目链接 大概题意就是告诉你有个n个小括号,每一个")"左边有多少个"("都告诉你了,然后让你求出每一对括号之间有多少对括号(包含自己本身). 思路: 我先计算每个")"左边有多少个"("要匹配,然后每遇到一个")",然后向前寻找第一个可以匹配的"(",找到后将其数量减一,这样的话在寻找的过程中经过了几个")"就表示这对括号里面有多少括号. //poj 1068 //…
http://poj.org/problem?id=1068 这道题是一道模拟的题目 题目大意呢,p代表前面的'('的个数,而w代表这个括号所包括的括号的个数: 给你p,要你求w: 解题思路: 首先,你肯定要把p所对应的那一个括号序列还原出来,当然,你也没必要说用字符把()表示出来,完全就可以用0和1分别代替左括号与右括号 其次,你就应该找出哪两个括号是相匹配的.比如说(((()()()))),p为456666,第一个)所匹配的为第4个左括号,第二个所匹配的为第5个左括号,第三个所匹配的为第6个…
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…
题目链接: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…
链接: 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…
转载请注明出处: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…
POJ的题目都是英文的,所以,,,还是直接贴代码吧 #include<stdio.h> int main(){ int x,y,z; int n,nm,max; scanf("%d",&n); while(n--){ int num[60]={0}; scanf("%d",&nm); for(x = 0;x < nm; x++){ scanf( "%d",&y); num[ y+x+1 ]=1; } fo…
                                                                                                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: 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…