Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
新手来挖坟~#include<iostream> #include<vector> using namespace std; class Parenthese { public: Parenthese(const size_t num) :num_lparen(num){}; ~Parenthese(){}; size_t num_lparen; size_t num_bet_left; std::vector<Parenthese>::iterator jump; }; int main() { int t, n, tem; vector<Parenthese> p; cin >> t; while (t--){ cin >> n; for (int i = 0; i != n; ++i){ cin >> tem; p.push_back(tem); } for (vector<Parenthese>::iterator i = p.begin(); i != p.end(); ++i){ if (i == p.begin()){ (*i).num_bet_left = (*i).num_lparen - 1; (*i).jump = i; cout << 1; } else{ if ((*i).num_lparen > (*(i - 1)).num_lparen){ (*i).num_bet_left = (*i).num_lparen - (*(i - 1)).num_lparen - 1; if ((*i).num_bet_left == 0)(*i).jump = i - 1; else (*i).jump = i; cout << " " << 1; } else{ (*i).num_bet_left = 0; vector<Parenthese>::iterator j = i - 1; while ((*j).num_bet_left == 0 && j != p.begin()) j = (*j).jump; (*i).jump = j; if (--(*j).num_bet_left == 0 && j != p.begin())(*j).jump = j - 1; cout << " " << i - j + 1; } } } cout << endl; p.clear(); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator