D - Decrease (Contestant ver.) AtCoder - 2661(找规律)

Problem Statement

We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N−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 N, and increase each of the other elements by 1.

It can be proved that the largest element in the sequence becomes N−1 or smaller after a finite number of operations.

You are given an integer K. Find an integer sequence ai such that the number of times we will perform the above operation is exactly K. 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×1016
Input

Input is given from Standard Input in the following format:

K
Output

Print a solution in the following format:

N
a1 a2 ... aN

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

Sample Input 1
0
Sample Output 1
4
3 3 3 3
Sample Input 2
1
Sample Output 2
3
1 0 3
Sample Input 3
2
Sample Output 3
2
2 2

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

Sample Input 4
3
Sample Output 4
7
27 0 0 0 0 0 0
Sample Input 5
1234567894848
Sample Output 5
10
1000 193 256 777 0 1 1192 1234567891011 48 425
思路:找规律发现
可以用50个数存,逆推,初始数组为:【0-49】
每经过50次操作,数组的每个数都会+1
然后要计算的就是k%50的操作
找规律发现,i<余数时,每个数+51-余数
i>余数时,每个数-余数
代码如下:
 1 #include<bits/stdc++.h>
 2 #include<iostream>
 3 using namespace std;
 4 #define ll long long
 5 
 6 int main()
 7 {
 8     ll k;
 9     while(cin >> k)
10     {
11         ll ro = k / 50;
12         ll yu = k % 50;
13         ll ty = ro - yu;
14         cout << 50 << endl;
15         for(int i = 0;i < 50;i++)
16         {
17             if(i < yu)
18             cout <<  i + ty + 51;
19             else
20             cout << i + ty;
21             if(i != 49)
22             cout << " ";
23         }
24         cout << endl;
25     }
26     return 0;
27 }
28 /*
29 1
30 50
31 50 0 1 2 3 4 5 6 7 8
32 9 10 11 12 13 14 15 16 17 18
33 19 20 21 22 23 24 25 26 27 28
34 29 30 31 32 33 34 35 36 37 38
35 39 40 41 42 43 44 45 46 47 48
36 */

 


转载于:https://www.cnblogs.com/lu1nacy/p/10013822.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值