7 条题解

  • 0
    @ 2025-7-12 9:09:42

    这道题肥肠煎蛋

    思路

    看最后一行,发现是1,3,6,10这样的数列,用 n 表示为 n(n+1)/2 n(n+1)/2 ,看第一列明显可以表示为 n(n+1)/2n+1n(n+1)/2-n+1 ,且数列是从左向右斜着递增,因此可得到以下代码

    #include<bits/stdc++.h>
    using namespace std;
    int n, a[10086];
    int main(){
    	cin >> n;
    	for(int i = 1; i <= n; i++)
    		a[i] = a[i-1] + i;
    	for(int i = 1; i <= n; i++){
    		for(int j = 1;j <= i;j++)
    			cout << a[n-i+j] - n + i << ' ';
    		cout << endl;
    	}
    	return 0;
    }

    信息

    ID
    68
    时间
    1000ms
    内存
    128MiB
    难度
    2
    标签
    递交数
    302
    已通过
    180
    上传者