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

做了这么久,首次一次AC,发帖留念。附上代码,仅供参考。

Posted by gtzygtzy at 2009-02-16 10:06:10 on Problem 1068
#include<iostream>
#include<string>
using namespace std;
string ss;
int n;
int p[25];
bool used[50];
void addleft(int x)
{
	for(int count=0;count<x;count++)
	{
		ss+='(';
	}
}
void addright()
{
	ss+=')';
}
void getss()
{
	for(int count=0;count<n;count++)
	{
		if(count==0) {addleft(p[0]);addright();}
		else{addleft(p[count]-p[count-1]);addright();}
	}
}
int match(int x)
{
	for(int count=x-1;count>=0;count--)
	{
		if(used[count]==false&&ss[count]=='(')
		{
			used[count]=true;
			used[x]=true;
			return (x-count+1)/2;
		}
	}
	return 0;
}
void slove()
{
	int first=0;
	for(int count=0;count<ss.length();count++)
	{
		if(ss[count]==')') {if(first!=0) cout<<" ";cout<<match(count);first++;}//可能不需要
	}
}
int main()
{
	int testnumber;
	cin>>testnumber;
	for(int count=1;count<=testnumber;count++)
	{
		cin>>n;
		ss.erase();
		memset(p,0,sizeof(p));
		memset(used,false,sizeof(used));
		for(int count2=0;count2<n;count2++)
		{
			cin>>p[count2];
		}
		getss();
		if(count!=1) cout<<endl;//可能不需要
		slove();
	}
	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