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 |
- -..Orz 数据好弱~~#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<int> p_vec,w_vec; vector<pair<char,bool> > bracket; void solve_prob() { int pos(0),val(0); for (vector<int>::iterator iter = p_vec.begin();iter != p_vec.end();++iter) { for (int i = 0;i != (*iter - val);++i) bracket.push_back(make_pair('(',false)); bracket.push_back(make_pair(')',false)); val = *iter; } //for (vector<pair<char,bool> >::iterator iter = bracket.begin();iter != bracket.end();++iter) // cout << iter->first; for (int i = 0;i != bracket.size();++i) { if (bracket[i].first == ')') { int pos(0); for (int j = i;;--j) { if (bracket[j].first == '(') { ++pos; if (!bracket[j].second) { w_vec.push_back(pos); bracket[j].second = true; break; } } } } } bool flag(false); for (vector<int>::iterator iter = w_vec.begin();iter != w_vec.end();++iter) { if (flag) cout << " "; else flag = true; cout << *iter ; } cout << endl; } int main() { int nr_cases; cin >> nr_cases; while (nr_cases--) { int n; cin >> n; for (int i = 0;i != n;++i) { int data; cin >> data; p_vec.push_back(data); } solve_prob(); p_vec.clear(); w_vec.clear(); bracket.clear(); } // system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator