hdu1134 Game of Connections(卡特兰数)
来源:互联网 发布:机场 知乎 编辑:程序博客网 时间:2024/06/05 05:34
卡特兰公式为:
(n+2)record[n+1]=(4n+2)record[n]
#include<stdio.h>#include<string.h>int record[110][110];int a1[110],weishu[110];void cheng(int a){ int i,m,c,chushu,temp; m=weishu[a-1]; c=0; for(i=0;i<=m;i++){ a1[i]=a1[i]*(4*a-2)+c; c=a1[i]/10000; a1[i]%=10000; } if(c>0){ ++m; a1[m]=c; } chushu=a+1,temp=a1[m]; if(m==0) a1[0]/=chushu; else{ for(i=m;i>=0;--i){ if(temp<chushu){ if(i==m) --m; else a1[i]=0; } else { a1[i]=temp/chushu; temp%=chushu; } temp=temp*10000+a1[i-1]; } } weishu[a]=m; for(i=0;i<=weishu[a];++i) record[a][i]=a1[i];}int main(){ int a,i,n; record[1][0]=1; weishu[1]=0; a1[0]=1; for(i=2;i<=100;i++) cheng(i); while(scanf("%d",&n)&&n!=-1){ printf("%d",record[n][weishu[n]]); for(i=weishu[n]-1;i>=0;--i) { printf("%.4d",record[n][i]); } printf("\n"); } return 0;}
java大数:
import java.util.*;import java.math.*;public class Main{ public static void main(String[] args){ int n; Scanner in=new Scanner(System.in); BigInteger one=BigInteger.ONE; BigInteger four=new BigInteger("4"); BigInteger two=new BigInteger("2"); BigInteger st=null; BigInteger t=null; while(in.hasNextInt()){ n=in.nextInt(); if(n==-1) break; t=BigInteger.ONE; for(int i=2;i<=n;i++) { st=new BigInteger(""+i); t=t.multiply(st.multiply(four).subtract(two)).divide(st.add(one)); } System.out.println(t); } }}
0 0
- hdu1134 Game of Connections(卡特兰数)
- hdu1134 Game of Connections 卡特兰数(大数)
- Game of Connections(卡特兰数)
- HDU1134——Game of Connections (大数乘法,除法)+ (卡特兰数列)
- POJ Game of Connections 卡特兰数
- Game of Connections 卡特兰数
- hdu 1134 Game of Connections(卡特兰数)
- POJ 2084 Game of Connections(卡特兰数,JAVA)
- Poj 2084 Game of Connections(高精度卡特兰数)
- HDU 1134 Game of Connections (高精度卡特兰数)
- poj 2084 Game of Connections (卡特兰数、大数)
- Game of Connections(标准卡特兰数及高精度)
- hdu1134(卡特兰数)
- hdu1134(卡特兰数)
- HDU 1134 Game of Connections 高精度卡特兰数
- POJ 2084 Game of Connections 卡特兰数
- 卡特兰数:poj 2084 Game of Connections+hdu 1023
- hdu 1134 Game of Connections 【卡特兰数+大数】
- 6.15 喜刷刷 oj 1 b 矩形类定义
- quartz入门(二)SimpleTrigger简单实例
- github 上 Fork 别人的项目后的常用的操作指南
- Red Hat Enterprise Linux 7(RHEL7)安装oracle11gr
- 编译speex过程
- hdu1134 Game of Connections(卡特兰数)
- 字典树:动物统计加强版 (nyoj)
- 05.ZooKeeper读书笔记之开源客户端(Curator)
- 最流行的android组件大全
- HTML CSS JS(一)
- MyEclipse移动Web模拟器指南(一)
- java线程同步-synchronized
- cocos获取当前时间
- iOS开发笔记--公司开发者账号申请详细教程