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 |
求指导 为何我用unsigned long就不对 改成long long就对了 ,求大牛帮忙#include <stdio.h> #include <iostream> using namespace std; long long Max=500000000; long long catalan[30]; int cur; void catalan_fun() { catalan[0]=catalan[1]=1; long long m=1; cur=2; while(m<Max) { catalan[cur]=catalan[cur-1]*(4*cur-2)/(cur+1); m+=catalan[cur]; cur++; } } void preorder(int n,long long k) { int s=0; int i=0; if (n==1) { printf("X"); return; } for (i=0;i<=n;i++)//先右后左 { if (s+catalan[i]*catalan[n-i-1]>=k) { break; } else { s+=catalan[i]*catalan[n-i-1]; } } if (i) { printf("("); preorder(i,(k-s-1)/catalan[n-i-1]+1); printf(")"); } printf("X"); if (n-i-1) { printf("("); preorder(n-i-1,(k-s-1)%catalan[n-i-1]+1); printf(")"); } } int main() { catalan_fun(); long long num; while(cin>>num&&num!=0) { long long k=0; int i; for (i=1;i<cur+10;i++) { if (k+catalan[i]>=num) { break; } else { k+=catalan[i]; } } preorder(i,num-k); printf("\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator