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

为什么总是WA,哪位帮忙看看啊

Posted by lsz at 2007-09-28 03:10:51 on Problem 1068
#include <iostream>

using namespace std;

int main()
{
	const int MAX = 10240;
	char p[MAX*2];
	int num[MAX];
	int weight[MAX*2];
	int n, i, j, k, pi, wi, times;

	cin>>times;
	while(times > 0)
	{
		times--;

		cin>>n;
		pi=0;
		for(i=0; i<n; i++)
		{
			cin>>num[i];

			if(i>0)
				k = num[i] - num[i-1];
			else
				k = num[i];

			for(j=0; j<k; j++)
			{
				p[pi] = '(';
				pi++;
			}
			p[pi] = ')';
			pi++;
		}

		//for(i=0; i<pi; i++)
		//	cout<<p[i]<<ends;
		//cout<<endl;

		wi = 0;
		weight[0] = 0;
		for(i=0; i<pi; i++)
		{
			if(p[i] == '(')
				weight[i+1] = weight[i] + 1;
			else
				weight[i+1] = weight[i] - 1;
		}

		//for(i=0; i<pi+1; i++)
		//	cout<<weight[i]<<ends;
		//cout<<endl;

		int begin, end, count;
		for(i=0; i<pi; i++)
		{
			if(p[i] == ')')
			{		
				end = i;
				begin = i-1;
				while(weight[begin]>=weight[end])
				{
					begin--;
				}

				count = 0;
				for(j=begin; j<=end; j++)
				{
					if(p[j] == ')')
						count++;
				}
				cout<<count<<ends;
			}
		}
		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