hdu4488 Faulhaber’s Triangle(模拟题)
Faulhaber’s Triangle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 157 Accepted Submission(s): 78
th powers of the first n integers
S(n,m) = SUM ( j= 1 to n)( j
m)
Can be written as a polynomial of degree m+1 in n:
S(n,m) = SUM (k = 1 to m+1)(F(m,k) *n
k)
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
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).
1 4 1
2 4 3
3 86 79
4 400 401
2 1/3
3 -22388337
4 1/401
#include<stdio.h> struct nod{
__int64 a,b;
}s[405][405]; __int64 gy(__int64 a,__int64 b)
{
__int64 temp;
if(b==0||a==0)
return 0;
if(a<0)
a=-a;
if(b<0)
b=-b;
if(a<b)
{
temp=a;
a=b;
b=temp;
}
while((temp=a%b))
{
a=b;
b=temp;
}
return b;
}
int Init()
{
int i,j,k,n;
__int64 t1,t2,temp;
s[0][1].a=1;
s[0][1].b=1;
s[1][1].a=1;
s[1][1].b=2;
s[1][2].a=1;
s[1][2].b=2;
for(i=2;i<401;i++)
{
for(j=2;j<=i+1;j++)
{
t1=i*s[i-1][j-1].a;
t2=j*s[i-1][j-1].b;
if((temp=gy(t2,t1)))
{
t1/=temp;
t2/=temp;
}
else
{
t1=0;
t2=1;
}
s[i][j].a=t1;
s[i][j].b=t2;
}
t1=0;
t2=1;
for(j=2;j<=i+1;j++)//2项开始求后面的和
{
t1=t2*s[i][j].a+t1*s[i][j].b;
t2=t2*s[i][j].b;
if((temp=gy(t1,t2)))
{
t1/=temp;
t2/=temp;
}
else
{
t1=0;
t2=1;
}
}
t1=t2-t1;
if((temp=gy(t1,t2)))
{
t1/=temp;
t2/=temp;
}
else
{
t1=0;
t2=1;
}
s[i][1].a=t1;
s[i][1].b=t2;
}
return 1;
}
int main()
{
int i,j,k,n,t,no,x,y;
Init();
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&no,&x,&y);
printf("%d ",no);
if(s[x][y].a==0)
printf("0\n");
else if(s[x][y].b==1)
printf("%I64d\n",s[x][y].a);
else printf("%I64d/%I64d\n",s[x][y].a,s[x][y].b);
}
return 0;
}
hdu4488 Faulhaber’s Triangle(模拟题)的更多相关文章
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
- cdoj 25 点球大战(penalty) 模拟题
点球大战(penalty) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- URAL 2046 A - The First Day at School 模拟题
A - The First Day at SchoolTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
随机推荐
- POJ 2442 Sequence 优先队列
题目: http://poj.org/problem?id=2442 #include <stdio.h> #include <string.h> #include <q ...
- 两台主机打通ssh
ssh打通基本概念:如果需要通过SSH进行远程登录,我们一般是需要手动输入密码,但如果将SSH之间的权限打通的话,就可以实现无密码登录.这对shell脚本的定时执行有很大的帮助. (一),生成秘钥,先 ...
- 在mesos上安装storm,并且执行wordcount测试程序
mesos上安装storm 1.基本说明 如果只用一句话来描述storm的话,可能会是这样:分布式实时计算系统.按照storm作者的说法,storm对于实时计算的意义类似于hadoop对于批处理的意义 ...
- PS字体工具字体显示不出来
显示一个小点:搜索了各种答案,扩大字号(最大72)更改前景色和背景色,最正确的解释就是分辨率太低,我发现分辨率是1,一般的设置成300,1分辨率情况下可以在图层那选择文字图层,然后按ctrl+t,拉大 ...
- BZOJ 1574: [Usaco2009 Jan]地震损坏Damage
Description 农夫John的农场遭受了一场地震.有一些牛棚遭到了损坏,但幸运地,所有牛棚间的路经都还能使用. FJ的农场有P(1 <= P <= 30,000)个牛棚,编号1.. ...
- js中实现页面跳转
1.在本页中跳转到指定页面 1.window.location.href方式 <script language="javascript" type="text ...
- WINDOWS下,中文JSON格式读取报错处理:ValueError: No JSON object could be decoded
File "C:\Python27\lib\json\__init__.py", line 290, in load **kw) File "C:\Python27\li ...
- 【UVA 10816】 Travel in Desert (最小瓶颈树+最短路)
[题意] 有n个绿洲, m条道路,每条路上有一个温度,和一个路程长度,从绿洲s到绿洲t,求一条道路的最高温度尽量小, 如果有多条, 选一条总路程最短的. InputInput consists of ...
- PHP数组和Json之间的互相转换 json_encode() 和 json_decode()
之所以要用到Json,很多时候是因为使用ajax对象时,程序与JS函数之间的数据交互.因为JS不认识PHP中的数组,PHP也不认识JS中的数组或对象.Json很好的解决了这个问题. Json简介 JS ...
- user模式下编译android 代码被proguard优化导致类和变量丢失
在Android项目中用到JNI,当用了proguard后,发现native方法找不到很多变量,原来是被produard优化掉了.所以,在JNI应用中该慎用progurad啊. 解决办法: 1.在An ...