AtCoder Regular Contest 079 D - Decrease (Contestant ver.)(构造题、读题要求高)

题目描述:

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:

KK

Output

Print a solution in the following format:

NN
a1a1 a2a2 ... aNaN

Here, 2≤N≤502≤N≤50 and 0≤ai≤1016+10000≤ai≤1016+1000 must hold.

Sample Input 1 Copy

Copy

0

Sample Output 1 Copy

Copy

4
3 3 3 3

Sample Input 2 Copy

Copy

1

Sample Output 2 Copy

Copy

3
1 0 3

Sample Input 3 Copy

Copy

2

Sample Output 3 Copy

Copy

2
2 2

The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1].

Sample Input 4 Copy

Copy

3

Sample Output 4 Copy

Copy

7
27 0 0 0 0 0 0

Sample Input 5 Copy

Copy

1234567894848

Sample 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;

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值