• Finite Encyclopedia of Integer Sequences


    Time limit : 2sec / Memory limit : 256MB

    Score : 800 points

    Problem Statement

    In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed.

    Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X⁄2)-th (rounded up to the nearest integer) lexicographically smallest one.

    Constraints

    • 1≤N,K≤3×105
    • N and K are integers.

    Input

    Input is given from Standard Input in the following format:

    K N
    

    Output

    Print the (X⁄2)-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS.


    Sample Input 1

    Copy
    3 2
    

    Sample Output 1

    Copy
    2 1 
    

    There are 12 sequences listed in FEIS: (1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3). The (12⁄2=6)-th lexicographically smallest one among them is (2,1).


    Sample Input 2

    Copy
    2 4
    

    Sample Output 2

    Copy
    1 2 2 2
    

    Sample Input 3

    Copy
    5 14
    

    Sample Output 3

    Copy
    3 3 3 3 3 3 3 3 3 3 3 3 2 2 

    题解:偶数的时候很好弄,输出k/2,k...k,奇数的时候,对与k/2.k/2 ...k/2 这个序列 里中间最近,与中间相差n/2 (证明 or 官方题解)个,即往前模拟

    code:

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    const int N = 3e5 + 10;
    const int mod = 1e9 + 7;
    int a[N];
    int main()
    {
        int n,k;
        scanf("%d%d",&k,&n);
        if(k&1)
        {
            for(int i = 1;i <= n;i++)
                a[i] = (k+1)/2;
            int m = n;
            for(int i = 1;i <= n/2;i++)
            {
                if(a[m] == 1)
                    m--;
                else
                {
                    a[m]--;
                    for(int j = m + 1;j <= n;j++)
                        a[j] = k;
                    m = n;
                }
            }
            for(int i = 1;i <= m;i++)
                printf("%d%c",a[i],i == m?'
    ':' ');
        }
        else
        {
            for(int i = 1;i <= n;i++)
                printf("%d%c",i == 1?k/2:k,i == n?'
    ':' ');
        }
        return 0;
    }
  • 相关阅读:
    ASP.NET Post方式提交
    MVC增加操作日志
    asp.net MVC 下拉多级联动及编辑
    redis基本数据类型之String
    关于idea下使用springinitializr创建项目时 初始化失败的解决
    Failed to read artifact descriptor for org.mybatis:mybatis:jar:2.2.1
    如何查看日志文件
    nginx 部署vue 以及同一端口下部署监听多个vue 项目
    JsonView 与JsonIgnore 使用
    vue 打包部署
  • 原文地址:https://www.cnblogs.com/lemon-jade/p/9417407.html
Copyright © 2020-2023  润新知