3 条题解

  • 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;
    }
    
    • 0
      @ 2025-7-12 20:45:56
      #include<bits/stdc++.h>
      using namespace std;
      int n,a[3005];
      bool b[13000];
      int main(){
      	cin>>n;
      	a[1]=1;
      	b[1]=1;
      	for(int i=2;i<=n;i++){
      		if(a[i-1]-i>0&&b[a[i-1]-i]==0){
      			a[i]=a[i-1]-i;
      			
      		}
      		else{
      			a[i]=a[i-1]+i;
      		}
      		b[a[i]]=1;
      	}
      	sort(a+1,a+n+1);
      	for(int i=1;i<=n;i++){
      		cout<<a[i]<<" ";
      	}
      	return 0;
      }
      
      • 0
        @ 2025-4-13 20:14:32
        #include <bits/stdc++.h>
        using namespace std;
        
        typedef long long ll ;
        
        ll a[3100]={0,1};
        int n;
        int k = 1;//a数组的当前长度
        
        int fd(ll m)
        {
            for(int i = 1; i <= k;i++)
            {
                if(m == a[i])return i;
            }
            return -1;
        }
        int main()
        {
            cin>>n;
            for(int i = 2; i <= n;i++)
            {
                //cout<<a[i]<<endl;
                ll t1 = a[i-1] - i;
                ll t2 = a[i-1] + i;
                if(t1 > 0 and fd(t1) == -1)a[i] = t1;
                else a[i] = t2;
                k++;
            }
            sort(a+1,a+k+1);
            for(int i = 1; i <= k;i++)
            {
                cout<<a[i]<<' ';
            }
        
            return 0;
        }
        
        • 1

        信息

        ID
        35274
        时间
        1000ms
        内存
        512MiB
        难度
        3
        标签
        递交数
        18
        已通过
        10
        上传者