杭电2032杨辉三角

来源:互联网 发布:js button 隐藏 编辑:程序博客网 时间:2024/04/29 03:13

/*做完此题虽然对于有些人来说水题一道但是想说的是为了推杨辉三角我用了两个小时而且是比赛中所以留作纪念*/

只做思路解说因为这题对编程能力要求低主要是推算能力,注意 两边都是1,中间 加2

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int n[1010];int main(){    int i, m, a=1, x, num, k, h, p, q, r, s;    while(scanf("%d", &m) != EOF){        x = 0;        r = 1;        i = 0;        num = 0;        p = 2;        q = 1;        while(x != m){            n[i] = 1;            if(x >= 2){                h = i;                k = x-1;                while(k){                n[h+1] = n[h-p] + n[h-q];                h++;                k--;            }            p++;            q++;            }            i = i + x;            n[i] = 1;            x++;            i++;        }         while( r != m+1 ){            s = r;            while(s){                cout<<n[num];                if(s>1) cout<<" ";                num++;                s--;            }            cout<<endl;            r++;         }         cout<<endl;    }    return 0;}

/*本想注释一下但是发现看了看主要是对数学知识的运用*/

1 0
原创粉丝点击