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

贴上代码~0MS

Posted by ljp at 2011-12-31 11:28:26 on Problem 1068
#include <iostream>
#include <string>
using namespace std;

int Sequence[50];
int PSequence[20];
int WSequence[20];
int index;
int Wi;

int main() {
	int caseNumber, pLen, d, sum;
	cin >> caseNumber;
	while (caseNumber-- > 0) {
		cin >> pLen;
		for (int i = 0; i < pLen; ++i) {
			cin >> PSequence[i];
		}
		//-1:(  1:)
		index = 0;
		Wi = 0;
		for (int i = 0; i < PSequence[0]; ++i) {
			Sequence[index++] = -1;
		}
		Sequence[index++] = 1;//第一个右括号
		for (int i = 1; i < pLen; ++i) {
			d = PSequence[i] - PSequence[i-1];
			for (int j = 0; j < d; ++j) {
				Sequence[index++] = -1;
			}
			Sequence[index++] = 1;
		}


		for (int i = 0; i < index; ++i) {
			if(Sequence[i] == 1) {
				sum = 0;
				for (int k = i; k >= 0; k--) {
					sum += Sequence[k];
					if(sum == 0) {
						WSequence[Wi++] = ((i-k)+1)/2;
						break;
					}

				}
			}
		}

		for (int i = 0; i < Wi; ++i) {
			cout<<WSequence[i]<<" ";
		}
		cout<<endl;
	}
	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