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

新手来挖坟~

Posted by sunl449554866 at 2014-08-16 17:57:39 on Problem 1068
#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:
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