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 __24__ at 2010-08-17 16:32:18 on Problem 1068
#include<stdio.h>
#include<string.h>
int a[25];
char s[150];
bool tag[150];
int main()
{
	int ncases,n,i,j,sta;
	//freopen("1.txt","r",stdin);
	scanf("%d",&ncases);
	while(ncases--)
	{
		scanf("%d",&n);
		for(i=1; i<=n; i++)
			scanf("%d",&a[i]);
		sta = 0;
		for(i=1; i<=n; i++)
		{
			for(j=sta+1; j<a[i]+i; j++)//表示从上一次的")"开始到这次的")"中间的全是"("
			{
				s[j] = 'L';
			}
			s[j] = 'R';
			sta = j;
		}
		memset(tag, false, sizeof(tag));
		for(i=1; i<=n; i++)
		{
			int cnt = 0;
			for(j=a[i]+i-1; j>=1; j--)//从")"向前找到第一个匹配的"("
			{
				if(s[j]=='L')
				{
					cnt++;
					if(!tag[j])
					{
						tag[j] = true;
						break;
					}
				}
			}
			if(i==1)
				printf("%d",cnt);
			else
				printf(" %d",cnt);
		}
		printf("\n");
	}
	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