【瞎搞】 HDU 1361 Parencodings 括号
给出一串括号 右括号的左边分别有多少个左括号
求右括号中 包含着几个完整的括号 (包括自己)
先按照输入构造出原括号
然后匹配下
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <string> #include <iostream> #include <algorithm> #include <sstream> #include <cmath> using namespace std; #include <queue> #include <stack> #include <vector> #include <deque> #include <set> #include <map> #include <time.h>; #define cler(arr, val) memset(arr, val, sizeof(arr)) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define IN freopen ("in.txt" , "r" , stdin); #define OUT freopen ("out.txt" , "w" , stdout); typedef long long LL; const int MAXN = 10014; const int MAXM = 41001; const int INF = 0x3f3f3f3f; const int mod = 1000000007; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int t,n,a; char s[444]; cin>>t; while(t--) { cin>>n; int last=0,tol=0; for(int i=0;i<n;i++) { cin>>a; for(;last<a;last++) s[tol++]='('; s[tol++]=')'; } s[tol]=0; // printf("%s\n",s);//括号 for(int i=0;i<n*2;i++) if(s[i]==')') { int x=1,ans=0; for(int j=i-1;j>=0;j--) { if(s[j]==')') x++; else x--; ans++; if(x==0) break; } printf("%d%c",ans/2+1,i==n*2-1?'\n':' '); } } return 0; }