题目描述:
Problem Statement
We have a sequence of length NN consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N−1N−1 or smaller.
- Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by NN, and increase each of the other elements by 11.
It can be proved that the largest element in the sequence becomes N−1N−1 or smaller after a finite number of operations.
You are given an integer KK. Find an integer sequence aiai such that the number of times we will perform the above operation is exactly KK. It can be shown that there is always such a sequence under the constraints on input and output in this problem.
Constraints
- 0≤K≤50×10160≤K≤50×1016
Input
Input is given from Standard Input in the following format:
KKOutput
Print a solution in the following format:
NN a1a1 a2a2 ... aNaNHere, 2≤N≤502≤N≤50 and 0≤ai≤1016+10000≤ai≤1016+1000 must hold.
Sample Input 1 Copy
Copy
0Sample Output 1 Copy
Copy
4 3 3 3 3Sample Input 2 Copy
Copy
1Sample Output 2 Copy
Copy
3 1 0 3Sample Input 3 Copy
Copy
2Sample Output 3 Copy
Copy
2 2 2The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].
Sample Input 4 Copy
Copy
3Sample Output 4 Copy
Copy
7 27 0 0 0 0 0 0Sample Input 5 Copy
Copy
1234567894848Sample Output 5 Copy
Copy
10 1000 193 256 777 0 1 1192 1234567891011 48 425
思路:
这题算是3/5自己做出来的吧,刚开始考虑两个数能不能构造出所有解,但是思考的方向不太对,然后看了一眼题解,看到“考虑两个数的情况,,,递推,,,”等词,想到了可以由0,1---1,2----2,3,每次2步构造(逆向考虑),奇数先转考虑偶数再暴力剩余次数即可,代码实现后交上去WA,再看题,题目对a【i】的数值有限制,因此N只能取50,然后有了N==2的思考,类比N==3,4,,,,50会发现同样规律,即0,1,2,,,n
到1,2,3,,,n+1需要n+1步,中间小插曲:类推的时候不同的N都当成+2处理了,应该是+N,犹豫了一段时间。
代码实现:
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>
#define LL long long
#define INF 1ll<<60
using namespace std;
const int N=2e5+100;
const int M=4e5+100;
const int mod=1e9+7;
LL arr[N];
int main() {
LL k;
while(cin>>k){
cout<<50<<endl;
LL tmp=k/50;
for(int i=1;i<=50;i++)arr[i]=(LL)i+tmp-1;
LL cnt=k%50;
for(int i=1;i<=cnt;i++){
for(int j=1;j<=50;j++){
if(j==i){
arr[j]+=50;
}else{
arr[j]-=1;
}
}
}
for(int i=1;i<=50;i++)cout<<arr[i]<<" ";
cout<<endl;
}
return 0;
}
THE END;