日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

中石油训练赛 - Faulhaber’s Triangle(打表)

發布時間:2024/4/11 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 中石油训练赛 - Faulhaber’s Triangle(打表) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

The sum of the m-th powers of the first n integers

can be written as a polynomial of degree m + 1 in n:

For example:
S(n, 1) = (1 + . . . + n) = (1/2) ? n2+ (1/2) ? n
S(n, 2) = (1 + . . . + n2) = (1/3) ? n3+ (1/2) ? n2+ (1/6) ? n
S(n, 3) = (1 + . . . + n3) = (1/4) ? n4+ (1/2) ? n3) + (1/4) ? n2
S(n, 4) = (1 + . . . + n4) = (1/5) ? n5+ (1/2) ? n4) + (1/3) ? n3?? (1/30) ? n
The coefficients F(m, k) of these formulas form Faulhaber’s Triangle:
1
1/2 1/2
1/6 1/2 1/3
0 1/4 1/2 1/4
-1/30 0 1/3 1/2 1/5
0 -1/12 0 5/12 1/2 1/6
1/42 0 -1/6 0 1/2 1/2 1/7
where rows m start with 0 (at the top) and columns k go from 1 to m + 1
Each row of Faulhaber’s Triangle can be computed from the previous row by:
a) The element in row i and column j (j > 1) is (i/j) ? (theelementaboveleft); 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 Triangle as decimal fractions in lowest terms .

?

輸入

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 ≤ m + 1).

?

輸出

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.

?

樣例輸入

4 1 4 1 2 4 3 3 86 79 4 400 401

樣例輸出

1 -1/30 2 1/3 3 -22388337 4 1/401題目鏈接:點擊查看

題目大意:給出公式:

  • 當j!=1時,
  • 當j==1時,
  • 初始化F(0,1)=1,求指定位置的值

    題目分析:這個題目給了很多無用的信息,但讀懂需要打表后寫一個函數打完表然后直接查詢就行了,為了防止爆范圍,我特地用了long long分別儲存分子和分母,并寫了一個化簡函數,每次都除以兩個數的gcd來約分,并且將分母上的符號轉移到分子上方便輸出,直接上代碼吧,簡單打表:

    #include<iostream> #include<string> #include<cstring> #include<cmath> #include<algorithm> using namespace std; typedef long long LL;const int N=500;LL a[N][N],b[N][N];//分子,分母 void huajian(LL &a,LL &b) {LL gcd=__gcd(a,b);a/=gcd;b/=gcd;if(a<0&&b<0)//如果都為負數,全部轉正{a=-a;b=-b;}if(a>=0&&b<0)//如果符號在分母上,則轉移到分子上{a=-a;b=-b;} }void init() {a[0][1]=1;b[0][1]=1;for(int i=1;i<=400;i++){LL suma=0;//suma和sumb儲存第2~i+1列的值的總和LL sumb=1;//初始化為0/1(分數形式)for(int j=2;j<=i+1;j++){a[i][j]=i*a[i-1][j-1];b[i][j]=j*b[i-1][j-1];huajian(a[i][j],b[i][j]);LL tempa=suma*b[i][j]+sumb*a[i][j];//根據通分求和化簡的LL tempb=sumb*b[i][j];huajian(tempa,tempb);suma=tempa;sumb=tempb;}a[i][1]=sumb-suma;//最后給F(i,1)賦值b[i][1]=sumb;huajian(a[i][1],b[i][1]);} }int main() {init();int w;cin>>w;while(w--){int num,x,y;scanf("%d%d%d",&num,&x,&y);printf("%d %lld",num,a[x][y]);if(b[x][y]!=1)printf("/%lld",b[x][y]);printf("\n");}return 0; }

    ?

    總結

    以上是生活随笔為你收集整理的中石油训练赛 - Faulhaber’s Triangle(打表)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。