Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

- -..Orz 数据好弱~~

Posted by CrazyApple at 2010-11-18 13:21:41 on Problem 1068
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator