zoukankan      html  css  js  c++  java
  • Decrease (Contestant ver.) AtCoder

    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
    嗯,找规律,可惜找不不到,然后经讲解恍然大悟,只需要最小值加n 剩下的减一就好了(就是递归 k-1成立k就成立)
    于是:
    #include <iostream>
    using namespace std;
    int main()
    {
        long long c[51];
        long long k,a,b;
        int j=0;
        scanf("%lld",&k);
        a=k/50;
        b=k%50;
        cout<<"50"<<endl;
        if(k%50==0)
    	{
            for(long long i=50+a-1;i>=a;i--)
                cout<<i<<" ";
        }
        else
    	{
            for(long long i=50+a;i>=a;i--)
    		{
                c[j]=i;
                j++;
            }
            for(long long i=0;i<51;i++)
    		{
                if(i==b)
                    continue;
                else
                    cout<<c[i]<<" ";
            }
        }
        cout<<endl;
        return 0;
    }
    /*
        49 48 47.........0    K=0
    50     48 47.........0    K=1
    50  49    47.........0    K=2
        50 49 48.........1    K=50
    */
    

      

  • 相关阅读:
    python基础===利用unittest进行测试用例执行的几种方式
    python基础===基于cv2的播放器
    python基础===对字符串进行左右中对齐
    python基础===拆分字符串,和拼接字符串
    移动端测试===从安卓手机截图到桌面的几行代码
    工具===激活xmind 8
    软件测试===测试用例基线结构
    python基础===猴子补丁
    python基础===数据伪造模块faker
    shell编程===执行shell脚本的四种方法
  • 原文地址:https://www.cnblogs.com/mozheaishang/p/10017449.html
Copyright © 2011-2022 走看看