7 条题解

  • 0
    @ 2026-3-29 12:58:28
    #include <iostream>
    #include <iomanip>
    using namespace std;
    short cnt = 1,a[31][31],n,mcnt;
    int main()
    {
        cin >> n;
        if (n == 1)
        {
            cout << 1;
            return 0;
        }
        for(int i = 1;i <= n;i++)
        	mcnt += i;
        a[n - 1][0] = 1;
        short x = n - 2,y = 0,xx = n - 3;
        while(cnt <= mcnt)
        {
            a[x][y] = ++cnt;
            if (x == n - 1)
            {
                x = xx;
                y = 0;
                xx--;
            }
            else
            {
                x++;
                y++;
            }
        }
        for (int i = 0;i < n;i++)
        {
            for (int j = 0;j < i + 1;j++)
                cout << setw(4) << a[i][j];
            cout << endl;
        }
        return 0;
    }

    信息

    ID
    1075
    时间
    1000ms
    内存
    128MiB
    难度
    6
    标签
    递交数
    408
    已通过
    129
    上传者