题解:P15861 [LBA-OI R3 A] A_Step_Back
dangerous_tDp · · 题解
一道瞪眼题,使用乡下粗鄙做法通过。
容易发现当
考察答案为
显然对于第
因为
不过为了防止
那么显然前面将有
把这种方式推广到
最后特判一下
so the code:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5;
int m, n;
signed main(){
cin >> m;
if (!m)return cout << "2\n2 3", 0;
for (int i = N; i - 1 && !n; i --)
if (i * (i - 1) / 2 <= m)n = i;
int d = m - n * (n - 1) / 2;
if (!d){
cout << n << '\n';
for (int i = 1; i <= n; i ++)cout << "1 ";
}
else{
cout << (++ n) << '\n';
for (int i = 1; i <= d; i ++)cout << "1 ";
cout << "2 ";
for (int i = d + 1; i < n; i ++)cout << "1 ";
}
return 0;
}
其中找