Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
半推公式的做法//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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator