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 |
这题太多人贴代码了,响应大家的号召#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator