2 条题解
-
1
按题意模拟即可。
#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
#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
- 难度
- 2
- 标签
- 递交数
- 10
- 已通过
- 6
- 上传者