题目链接:http://acm.tju.edu.cn/toj/showp2969.html
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 1436 Accepted Runs: 434
Sojib is a student of class VI. He just learned the algebraic equation (a+b)^2.
(a+b)^2 = (a+b)*(a+b) = a*a+a*b+a*b+b*b = a^2+2*a*b+b^2After sometimes he thought, if I could solve it for (a+b)^3. So he starts with the same way as he did it for (a+b)^2. After performing the calculation he has found that the coefficient for (a+b)^3 are 1, 3, 3, 1. Here the order is taken as the decreasing order of the power of a . Now he thinks if I could solve it for higher terms of the power of (a+b). But he felt bored after sometimes as so much multiplication has to perform. But he is very much interested to know what will be the sequence of co-efficient if it arranged for decreasing order of the power of a. He heard that a programming contest is arranged for 05 batch of CUET. He knows all of the students of 05 are good at programming. So he asked you, if you can help him by telling him the sequence of coefficients in decresing order of the power of a.
Input
Input consists of one integer n (0≤n≤50) that represents the power of (a+b). Input will be terminated by a negative number.Output
For each number just print the sequence of co-efficients in decreasing order of the power of a. There will be a space in between every number in the sequence.Sample Input
3 7 -1
Sample Output
1 3 3 1 1 7 21 35 35 21 7 1
Problem Setter : John
Source: CUET Easy Contest
水题,但是错了好多次,这个题有点j,也是由于粗心,以为只要用n!=0来确保输入结束就可以了,没有考虑错误的输入,类似n=-2等,最后才发现改成n>=0才对。主要是题目说了n的范围,所以也没多想。。。
#include <stdio.h>
int main(){
long long a[51];
int n;
double tmp;
while(scanf("%d",&n) &&n>=0){
a[0]=a[n]=1;
for(int i=1;i<=n/2;i++){
tmp=1.0;
for(int j=0;j<i;j++)
tmp*=(double)(n-j)/double(i-j);
a[i]=a[n-i]=tmp+0.5;
}
for(int i=0;i<n;i++)
printf("%lld ",a[i]);
printf("%lld\n",a[n]);
}
}