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

求安慰,测试用例都过了啊 为啥还是wa呢 ///代码搓 见谅

Posted by ghx at 2010-12-06 15:17:00 on Problem 1068
//还原括号 然后再回溯 最基本的思想 没有优化

#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:
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