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 darkcaller at 2010-10-29 00:11:01 on Problem 1068
//a[i]实际上是‘(’的个数,i是第i+1个‘)’,所以只要判断两个‘)’之间是左括号多还是右括号多,左括号多则不包括前一个左括号,数数两个括号之间的右括号数就行了
#include<stdio.h>
int main()
{
	int i,j,t,n;
	int a[100];
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		scanf("%d",&a[0]);
		printf("1 ");
		for(i=1;i<n;i++){
			scanf("%d",&a[i]);
			if(a[i]>a[i-1])printf("1 ");
			else 
				for(j=i-1;j>=0;j--){
					if((i-j)<=(a[i]-a[j])){
						printf("%d ",i-j);
						break;
					}
					else if((!j)&&(i>(a[i]-a[0])))printf("%d ",i+1);
				}
		}
		printf("\n");
	}
}

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