| ||||||||||
| 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 | |||||||||
我哪里错了,我没看出来什么地方错误了,所有的数据都是对的!!!#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
long int a[100]={0,1,3,8,22,64,196,625,2055,6917,23713,82499,290511,1033411,3707851,13402696,48760366,178405156,656043856};
long int b[100]={1,1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845,35357670,129644790,477638700};
string func(int i,int pth){ //p代表有几个棒子,pth代表p个棒子的第pth中排列
if(i==0)return "";
else if(i==1)return "(X)";
else if(i==2){
if(pth==1)return"(X(X))";
else return "((X)X)";
}
int last=pth;
int sum=0;
int left;int right;
for(int s=0;s<i;s++){
sum+=b[s]*b[i-s-1];
if(sum>=last){
left=s;right=i-s-1;
sum-=b[s]*b[i-s-1];
break;
}
}
for(s=1;s*b[right]<=last-sum;s++){}
return ("("+func(left,s-1)+"X"+func(right,last-sum-(s-1)*b[right])+")");
}
string cal(int n){
if(n==0)return "";
else if(n==1)return "X";
else if(n==2)return"X(X)";
else if(n==3)return "(X)X";
for(int i=0;a[i]<n;i++){}
int last=n-a[i-1];
int sum=0;
int left;int right;
for(int s=0;s<i;s++){
sum+=b[s]*b[i-s-1];
if(sum>=last){
left=s;right=i-s-1;
sum-=b[s]*b[i-s-1];
break;
}
}
for(s=1;s*b[right]<=last-sum;s++){}
return (func(left,s-1)+"X"+func(right,last-sum-(s-1)*b[right]));
// return "";
}
void main(){
int n;
while(1){
cin>>n;
if(n==0)break;
cout<<cal(n)<<endl;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator