HDU 4488 Faulhaber’s Triangle (数学题)
来源:互联网 发布:淘宝dnf游戏币交易 编辑:程序博客网 时间:2024/06/09 18:53
Faulhaber’s Triangle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 237 Accepted Submission(s): 126
Total Submission(s): 237 Accepted Submission(s): 126
Problem Description
The sum of the mth powers of the first n integers
S(n,m) = SUM ( j= 1 to n)( jm)
Can be written as a polynomial of degree m+1 in n:
S(n,m) = SUM (k = 1 to m+1)(F(m,k) *nk)
Fo example:
The coefficients F(m,k) of these formulas form Faulhaber‘s Tr angle:
where rows m start with 0 (at the top) and columns k go from 1 to m+1
Each row of Faulhaber‘s Tr angle can be computed from the previous row by:
a) The element in row i and column j ( j>1) is (i/j )*(the element above left); that is:
F(i,j ) = (i/j )*F(i-1, j-1)
b) The first element in each row F(i,1) is chosen so the sum of the elements in the row is 1
Write a program to find entries in Faulhaber‘s Tr angle as decimal f actions in lowest terms
S(n,m) = SUM ( j= 1 to n)( jm)
Can be written as a polynomial of degree m+1 in n:
S(n,m) = SUM (k = 1 to m+1)(F(m,k) *nk)
Fo example:
The coefficients F(m,k) of these formulas form Faulhaber‘s Tr angle:
where rows m start with 0 (at the top) and columns k go from 1 to m+1
Each row of Faulhaber‘s Tr angle can be computed from the previous row by:
a) The element in row i and column j ( j>1) is (i/j )*(the element above left); that is:
F(i,j ) = (i/j )*F(i-1, j-1)
b) The first element in each row F(i,1) is chosen so the sum of the elements in the row is 1
Write a program to find entries in Faulhaber‘s Tr angle as decimal f actions in lowest terms
Input
The first line of input contains a single integer P, (1 <= P <= 1000), which is the number of data sets that follow. Each data set should be processed identically and independently
Each data set consists of a single line of input consisting of three space separated decimal integers The first integer is the data set number. The second integer is row number m, and the third integer is the index k within the row of the entry for which you are to find F(m, k), the Faulhaber‘s Triangle entry (0 <= m <= 400, 1 <= k <= n+1).
Each data set consists of a single line of input consisting of three space separated decimal integers The first integer is the data set number. The second integer is row number m, and the third integer is the index k within the row of the entry for which you are to find F(m, k), the Faulhaber‘s Triangle entry (0 <= m <= 400, 1 <= k <= n+1).
Output
For each data set there is a single line of output. It contains the data set number, followed by a single space which is then followed by either the value if it is an integer OR by the numerator of the entry, a forward slash and the denominator of the entry.
Sample Input
41 4 12 4 33 86 794 400 401
Sample Output
1 -1/302 1/33 -223883374 1/401
Source
Greater New York 2012
Recommend
liuyiding
题意:
题目中有很多没有用的信息,主要内容为:
1.注意第二个图即F(m, k)图,给你m和k,要输出F(m, k)。
2.图中的F(m, k)公式:F(i,j ) = (i/j )*F(i-1, j-1),( j>1)
3.图中每行的和为1
#include <stdio.h>//#define LL long long//#define LLS "%" "l" "l" "d"#define LL __int64 #define LLS "%" "I" "6" "4" "d"struct node { LL fz,fm;}FF[405][405];//LL gcd(LL a, LL b) { //if(b == 0) return a; //return gcd(b,a%b);//}LL gcd(LL a, LL b) { LL temp; if(a < 0) a = -a; if(b < 0) b = -b; while(b > 0) { temp = a; a = b; b = temp % b; } return a;}void init() { LL tempi,tempj,sumfz,sumfm,fz,fm,gg; FF[0][1].fz = 1; FF[0][1].fm = 1; for(int i=1; i<=400; i++) { sumfz = 0; sumfm = 1; for(int j=2; j<=i+1; j++) { if(FF[i-1][j-1].fz == 0) { FF[i][j].fz = 0; FF[i][j].fm = 1; } else { fz = FF[i-1][j-1].fz; fm = FF[i-1][j-1].fm; gg = gcd(i,j); //if(gg < 0) gg = -gg; tempi = i / gg; tempj = j / gg; gg = gcd(tempj,fz); //if(gg < 0) gg = -gg; tempj = tempj / gg; fz = fz / gg; gg = gcd(tempi,fm); //if(gg < 0) gg = -gg; tempi = tempi / gg; fm = fm / gg; FF[i][j].fz = tempi * fz; FF[i][j].fm = tempj * fm; //if(FF[i][j].fz == 0) //FF[i][j].fm = 1; sumfz = sumfz * FF[i][j].fm + sumfm * FF[i][j].fz; sumfm = sumfm * FF[i][j].fm; gg = gcd(sumfz,sumfm); //if(gg < 0) gg = -gg; sumfz = sumfz / gg; sumfm = sumfm / gg; if(sumfz == 0) sumfm = 1; } } FF[i][1].fz = sumfm - sumfz; FF[i][1].fm = sumfm; }}int main() { //freopen("in.txt","r",stdin); int t,m,k,cas; init(); scanf("%d",&t); while(t--) { scanf("%d%d%d",&cas,&m,&k); printf("%d ",cas); if(FF[m][k].fm == 1) { printf(LLS"\n",FF[m][k].fz); } else { printf(LLS"/"LLS"\n",FF[m][k].fz,FF[m][k].fm); } }}
- HDU 4488 Faulhaber’s Triangle (数学题)
- hdu 4488 Faulhaber’s Triangle
- hdu 4488 Faulhaber’s Triangle
- HDU 4488 Faulhaber’s Triangle
- HDU 4488Faulhaber’s Triangle(模拟 题目有公式)
- hdu4488 Faulhaber’s Triangle
- Uva 6176 Faulhaber's Triangle
- hdu4488 Faulhaber’s Triangle(模拟)
- hdu4488 Faulhaber’s Triangle(模拟题)
- hdu-4466-Triangle 数学题
- UVALive 6176 Faulhaber's Triangle C++大数模拟
- HDU 2832 Snail’s trouble(数学题)
- hdu 3876 A pupil’s problem(简单数学题)
- hdu 2368 Alfredo's Pizza Restaurant(简单数学题)
- HDU 3105 Fred's Lotto Tickets(数学题)
- HDU 5135 Little Zu Chongzhi's Triangles(数学题)
- UVA 11401 - Triangle Counting (数学题)
- NYOJ 982 Triangle Counting (数学题)
- Java高级特性之枚举(二)
- 详解PHP的_get()和_set()方法
- Lua脚本在C++下的舞步(入门指引)
- 利用正则表达式统计某个某个文件夹下所有java文件的 空格行数、注释行数、和代码行数
- 自制即时通信系统:socket网络编程(总结)
- HDU 4488 Faulhaber’s Triangle (数学题)
- C++进阶——初始化列表
- 可穿戴设备,包括智能手表,智能眼镜,智能手链等
- 笔试题1
- 叉姐的魔法训练(第十三课)---- 无法成为勇者的我,无可奈何决定去打工
- 盘点黑客攻击途径:最常用的7个策略及简单的防护方法
- Android中Handler机制的详解
- 蓝牙基础
- Android Framework---styles.xml