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 |
求安慰,测试用例都过了啊 为啥还是wa呢 ///代码搓 见谅//还原括号 然后再回溯 最基本的思想 没有优化 #include <stdio.h> int main() { int t,n,par; int i,j,k,tag; int w[50],p[50],s[100]; scanf("%d",&t); for(i=0;i<t;i++) { par=0; scanf("%d",&n); for(j=0;j<n;j++){ scanf("%d",&p[j]); if(j==0){ for(k=0;k<p[j];k++) s[k]=-1; s[p[j]]=1; par=p[j]; } else{ for(k=p[j-1];k<p[j];k++) s[++par]=-1; s[++par]=1; } } /*for(j=0;j<par;j++) printf("%d ",s[j]); printf("%d\n",s[par]);*/ tag=0; memset(w,0,50); for(j=0;j<=par;j++){ if(s[j]==1){ if(s[j-1]==-1){ w[tag++]=1; s[j-1]=0; } else{ for(k=j-2;k>=0;k--){ if(s[k]==0){ w[tag]++; } else if(s[k]==-1){ s[k]=0; w[tag]++; break; } } tag++; } } } for(j=0;j<n-1;j++) printf("%d ",w[j]); printf("%d\n",w[n-1]); } //system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator