poj1068 Parencodings 模拟水题
2014-05-11 15:53
411 查看
///2014.3.8 ///poj1068 //time:0MS /** *对于给出的原括号串,存在两种数字密码串: *1.p序列:当出现匹配括号对时, * 从该括号对的右括号开始往左数, * 直到最前面的左括号数,就是pi的值。 *2.w序列:当出现匹配括号对时, * 包含在该括号对中的所有右括号数(包括该括号对), * 就是wi的值。 *题目的要求:对给出的p序列,求出对应的w序列。 */ #include <iostream> #include <cstdio> #include <cstring> #include <deque> using namespace std; int main( ) { // freopen("in","r",stdin); // freopen("out","w",stdout); int T; ///case数 scanf("%d",&T); while( T-- ){ int n; scanf("%d",&n); int seq ; ///存储输入的p序列 for(int i=0 ; i<n ; i++) scanf("%d",&seq[i]); ///用p序列还原括号序列 deque<char> parentheses; int existing = 0; for(int i=0 ; i<n ; i++){ for(int j=existing ; j<seq[i] ; j++){ parentheses.push_back('('); existing++; } parentheses.push_back(')'); } ///输出w序列 bool used[2*n]; memset(used,0,sizeof(bool)*2*n); for(int i=0 ; i<parentheses.size() ; i++){ if( parentheses[i]==')' ){ int num = 0; for(int j=i-1 ; j>=0 ; j--){ if( used[j] && parentheses[j]=='(' ){ num++; } if( !used[j] && parentheses[j]=='(' ){ num++; used[j] = true; break; } } printf("%d ",num); } } cout<<endl; } return 0; }
相关文章推荐
- POJ 1068:Parencodings:模拟水题
- HDU 1361 & POJ 1068 Parencodings(模拟)
- [ACM] POJ 1068 Parencodings(模拟)
- [poj1068]Parencodings_模拟
- POJ1068 Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings——模拟
- poj 1068 Parencodings 模拟
- POJ 1068 Parencodings 模拟 难度:0
- POJ 1068-Parencodings(模拟)
- poj 1068 Parencodings (模拟)
- POJ 1068 Parencodings 模拟 栈操作
- POJ1068 Parencodings(模拟)
- poj1068 Parencodings 模拟 栈
- POJ 1068 Parencodings (模拟)
- Parencodings(poj1068简单模拟)
- poj 1068 Parencodings(模拟)
- POJ 1068 Parencodings 模拟-括号匹配
- poj1068 Parencodings【模拟】【刷题计划】
- poj 1068 模拟水题