1 条题解

  • 1
    @ 2025-3-22 15:07:52

    按题意模拟即可。

    #include <bits/stdc++.h>
    #define endl '\n'
    
    using namespace std;
    
    typedef long long ll;
    
    ll a[3100];
    ll b[3100];
    int n, k;
    
    bool check(ll l) {
        for (int i = 1; i <= k; i++)
            if (b[i] == l)
                return false;
        return true;
    }
    
    int main() {
        cin >> n;
        a[1] = 1;
        b[++k] = 1;
        
        for (int i = 2; i <= n; i++) {
            if (a[i - 1] - i > 0 && check(a[i - 1] - i)) {
                b[++k] = a[i - 1] - i;
                a[i] = a[i - 1] - i;
            }
                
            else {
                b[++k] = a[i - 1] + i;
                a[i] = a[i - 1] + i;
            } 
        }
    
        sort(a + 1, a + n + 1);
    
        for (int i = 1; i <= n; i++)
            cout << a[i] << " ";
        return 0;
    }
    

    信息

    ID
    35274
    时间
    1000ms
    内存
    512MiB
    难度
    2
    标签
    递交数
    8
    已通过
    4
    上传者