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

请教大牛,这份代码为什么是wrong answer啊...

Posted by qiqilrq at 2007-10-29 10:28:22 on Problem 1095
#include <iostream>
using namespace std;
#define maxn 20
int Catl[maxn];
string tree(int n,int k){
    if(n<2) return "X";
    int t=n-1,j;
    for(j=0;j<=t;j++)
        if(k < Catl[j]*Catl[t-j]){
            int Ln=j;
            int Rn=t-Ln;
            int Lk=k/Catl[Rn];
            int Rk=k%Catl[Rn];
            string ret("X");
            if(Ln>0)
                ret = "(" + tree(Ln,Lk) + ")" + ret;
            if(Rn>0)
                ret = ret + "(" + tree(Rn,Rk) + ")";
            return ret;
        }
        else 
            k-=Catl[j]*Catl[t-j];
}
int main(){
	int i,j,t,n; 
	Catl[0]=1;
	for(i=1;i<maxn;i++) {
	    for(j=0;j<i;j++)
	    {
            Catl[i]+=Catl[j]*Catl[i-j-1];
        }
        cout<<Catl[i]<<endl;
    }
	while(cin>>n && n){
        for(t=0;t<maxn;t++)
        if(n<Catl[t])
            break;
        else
            n-=Catl[t];
        cout<<tree(t,n)<<endl;
    }
}

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