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 StepByStepCnmLife at 2015-05-11 22:48:07 on Problem 1068
#include <stdio.h >
#include <stdlib.h>
#define used  1
#define fresh 0
#define MAX   40
typedef struct node{
    int lor;  //left or right
    int status;
}node;
node sequence[MAX];//还原序列
int  p[MAX];
int solve(int len)
{
    int i,j,k,cnt;
    p[0]=0;
    for(i=1,k=0;i<=len;i++)
    {
        for(j=0;j<(p[i]-p[i-1]);j++)
        {
            sequence[k].lor=0;
            sequence[k].status=fresh;
            k++;
        }
        sequence[k].lor=1;
        sequence[k].status=fresh;
        k++;//k代表原始序列的长度
    }
    for(i=0;i<k;i++)
    {
        if(sequence[i].lor==0)continue;
        sequence[i].status=used;
        j=i-1;
        cnt=1;
        while(sequence[j].status==used)
        {
            if(sequence[j].lor==1)cnt++;
            j--;
        }
        sequence[j].status=used;
        printf("%d ",cnt);
    }
    printf("\n");
}
int main()
{
    int cases,i,j,len,k,m;
    scanf("%d",&cases);
    for(i=0;i<cases;i++)
    {
        scanf("%d",&len);
        for(j=1;j<=len;j++)
            scanf("%d",&p[j]);
        solve(len);
    }
    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