首页 > 代码库 > 【高精度】NCPC 2014 C catalansqure

【高精度】NCPC 2014 C catalansqure

题目链接:

  http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1789

题目大意:

  求大卡特兰数。。公式如下。输入n求Sn(n<=5000)

技术分享技术分享

题目思路:

  【高精度】

  Sn=Cn+1。直接压四位高精度算一遍就好。只要写高精度乘单精度,高精度除单精度。

 

技术分享
 1 // 2 //by coolxxx 3 //#include<bits/stdc++.h> 4 #include<iostream> 5 #include<algorithm> 6 #include<string> 7 #include<iomanip> 8 #include<map> 9 #include<stack>10 #include<queue>11 #include<set>12 #include<bitset>13 #include<memory.h>14 #include<time.h>15 #include<stdio.h>16 #include<stdlib.h>17 #include<string.h>18 //#include<stdbool.h>19 #include<math.h>20 #define min(a,b) ((a)<(b)?(a):(b))21 #define max(a,b) ((a)>(b)?(a):(b))22 #define abs(a) ((a)>0?(a):(-(a)))23 #define lowbit(a) (a&(-a))24 #define sqr(a) ((a)*(a))25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))26 #define mem(a,b) memset(a,b,sizeof(a))27 #define eps (1e-8)28 #define J 1000029 #define mod 100000000730 #define MAX 0x7f7f7f7f31 #define PI 3.1415926535897932332 #define N 2000433 using namespace std;34 typedef long long LL;35 int cas,cass;36 int n,m,lll,ans;37 int a[N];38 void gjdchengdjd(int a[],int b)39 {40     int i;41     for(i=1;i<=a[0];i++)42         a[i]*=b;43     for(i=1;i<=a[0];i++)44         a[i+1]+=a[i]/J,a[i]%=J;45     while(a[a[0]+1])a[0]++;46 }47 void gjdchudjd(int a[],int b)48 {49     int i;50     for(i=a[0];i>1;i--)51         a[i-1]+=(a[i]%b)*J,a[i]/=b;52     a[1]/=b;53     while(!a[a[0]] && a[0]>1)a[0]--;54 }55 void gjdprint(int a[])56 {57     int i;58     printf("%d",a[a[0]]);59     for(i=a[0]-1;i;i--)60         printf("%04d",a[i]);61     puts("");62 }63 int main()64 {65     #ifndef ONLINE_JUDGE66 //    freopen("1.txt","r",stdin);67 //    freopen("2.txt","w",stdout);68     #endif69     int i,j,k;70     int x,y,z;71 //    for(scanf("%d",&cass);cass;cass--)72 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)73 //    while(~scanf("%s",s+1))74     while(~scanf("%d",&n))75     {76         n++;77         a[0]=a[1]=1;78         for(i=n+1;i<=n+n;i++)79             gjdchengdjd(a,i);80         for(i=2;i<=n+1;i++)81             gjdchudjd(a,i);82         gjdprint(a);83     }84     return 0;85 }86 /*87 //88 89 //90 */
View Code

 

【高精度】NCPC 2014 C catalansqure