POJ 3199 Uncle Jack(高精度加速乘)
2017-07-25 15:53
477 查看
Dear Uncle Jack is willing to give away some of his collectable CDs to his nephews. Among the titles you can find very rare albums of Hard Rock, Classical Music, Reggae and much more; each title is considered to be unique. Last week he was listening to one
of his favorite songs, Nobody’s fool, and realized that it would be prudent to be aware of the many ways he can give away the CDs among some of his nephews.
So far he has not made up his mind about the total amount of CDs and the number of nephews. Indeed, a given nephew may receive no CDs at all.
Please help dear Uncle Jack, given the total number of CDs and the number of nephews, to calculate the number of different ways to distribute the CDs among the nephews.
Input
The input consists of several test cases. Each test case is given in a single line of the input by, space separated, integers N (1 ≤ N ≤ 10) and D (0 ≤ D ≤ 25), corresponding to the number of nephews and the number of
CDs respectively. The end of the test cases is indicated with N = D = 0.
Output
The output consists of several lines, one per test case, following the order given by the input. Each line has the number of all possible ways to distribute D CDs among N nephews.
Sample Input
Sample Output
题解:
很简单的一道题。。每一件礼物都可以给任何一个人,就是n的d次方,由于结果很大要高精度,一开始除10模10就tle了,老刘改成了10000就ac了
代码:
of his favorite songs, Nobody’s fool, and realized that it would be prudent to be aware of the many ways he can give away the CDs among some of his nephews.
So far he has not made up his mind about the total amount of CDs and the number of nephews. Indeed, a given nephew may receive no CDs at all.
Please help dear Uncle Jack, given the total number of CDs and the number of nephews, to calculate the number of different ways to distribute the CDs among the nephews.
Input
The input consists of several test cases. Each test case is given in a single line of the input by, space separated, integers N (1 ≤ N ≤ 10) and D (0 ≤ D ≤ 25), corresponding to the number of nephews and the number of
CDs respectively. The end of the test cases is indicated with N = D = 0.
Output
The output consists of several lines, one per test case, following the order given by the input. Each line has the number of all possible ways to distribute D CDs among N nephews.
Sample Input
1 20 3 10 0 0
Sample Output
1 59049
题解:
很简单的一道题。。每一件礼物都可以给任何一个人,就是n的d次方,由于结果很大要高精度,一开始除10模10就tle了,老刘改成了10000就ac了
代码:
#include<iostream> #include<stdio.h> #include<map> #include<algorithm> #include<math.h> #include< 4000 ;queue> #include<stack> #include<string> #include<cstring> using namespace std; int t[105],m,n,b[105]; void cheng(int a[],int x)//大数乘法 { int i,j,w=0; for(i=0;i<=8;i++) t[i]=0; for(i=0;i<=8;i++) { t[i]+=a[i]*x+w; w=t[i]/10000;//进位处理 t[i]%=10000; } } int main() { int i; while(scanf("%d%d",&m,&n),m||n) { if(!n) { printf("1\n"); continue; } memset(b,0,sizeof(b)); b[0]=m; n--; while(n--) { cheng(b,m); for(i=0;i<=8;i++) b[i]=t[i]; } for(i=8;!b[i];i--);//去掉前导0 printf("%d",b[i]);第一位直接输出 i--; for(;i>=0;i--) printf("%04d",b[i]);//因为是4位4位输出,不足补0 printf("\n"); } return 0; }
相关文章推荐
- POJ 3199 Uncle Jack大数的幂 利用高精度乘法模板
- POJ 3199 Uncle Jack大数的幂 利用高精度乘法模板
- POJ 3199 Uncle Jack (高精度)
- poj 3199 Uncle Jack
- POJ 3199 Uncle Jack 笔记
- poj 3199 高精度 java
- POJ 3199 Uncle Jack(JAVA练习)
- POJ 3181 Dollar Dayz 完全背包 + 高精度
- POJ1001 求高精度幂 ACM解题报告(高精度模板)
- POJ 2109 Power of Cryptography【高精度+二分 Or double水过~~】
- poj 2506 Tiling 高精度
- poj2109-二分+高精度
- POJ 1001-Exponentiation(NYOJ 155 求高精度幂):大数问题
- POJ之路1--1001高精度求幂级数
- 【POJ】 1001-Exponentiation 【高精度乘法】
- poj 1625(ac自动机+dp+高精度)
- POJ 1001 高精度实数相乘与快速幂
- poj 1001(高精度)
- poj1001 高精度
- Dollar Dayz POJ - 3181 dp,完全背包,简单高精度加法