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

Re:将那a[18]改成 656043856 ,不通过找我

Posted by wotiannu at 2009-01-13 22:29:13 on Problem 1095
In Reply To:Re:将那a[18]改成 656043856 ,不通过找我 Posted by:hahaxiao at 2005-09-03 20:23:13
#include<iostream>//45975可以,45976就不行了 
using namespace std;
long a[19]={1,1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845,35357670,129644790,477638700};
void LR(long node,long x);
long ntree(long n,long *x)
{
    long sum=0;
    long node;
    for(node=1;node<19;node++)
             {
             if(sum+a[node]>=n) break;
             else  sum=sum+a[node];
             }
            *x=n-sum;
    return node;
}
void print(long L,long Lx,long R,long Rx)
{
     if(L>0)
     {
          printf("(");
          LR(L,Lx);
          printf(")");
          
      }
      printf("X");
      if(R>0)
      {
           printf("(");
           LR(R,Rx);
           printf(")");
       }
}
void LR(long node,long x)
{
    long Lx,Rx,L,R;
    long sum=0;
    for(L=0;L<node;L++)
    {
                       sum=sum+a[L]*a[node-1-L]; 
                       if(sum>=x)  break;
    }
    if(sum==x)
    {
     R=node-L-1;
     Rx=a[R];
     Lx=1;
    }
    else
    {
        Rx=x-sum+a[L]*a[node-1-L];
        R=node-L-1;
        if(R<0)  {L--;R=node-L-1;}
        Lx=1;
        if(Rx>=a[R])
        {
                   Lx=Rx-a[R]+1;
                   Rx=a[R];
        }
          
    }
   
    print(L,Lx,R,Rx);
}

int main(void)
{    
    long n,node,x;
    scanf("%d",&n);
    while(n)
    {
            if(n==1)  printf("X");
            else             
            {
            node=ntree(n,&x);  //表示树是含有node个结点的第x种情况的树 
            LR(node,x);
            }
            printf("\n");
            scanf("%d",&n);
    }
    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