zoukankan      html  css  js  c++  java
  • Finite Encyclopedia of Integer Sequences(找规律)

    6617: Finite Encyclopedia of Integer Sequences

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 375  解决: 91
    [提交] [状态] [讨论版] [命题人:admin]

    题目描述

    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 is given from Standard Input in the following format:
    K N

    输出

    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.

    样例输入

    3 2
    

    样例输出

    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).

    来源/分类

    ABC077&ARC084 

    思路:

    1、k为偶数,序列为:k/2、k、k、k.......,共n个数。

    2、k为奇数,序列为:(k+1)/2、(k+1)/2、(k+1)/2、(k+1)/2.......再往前推2/n个。

    #include <bits/stdc++.h>
    using namespace std;
    int n,k;
    int a[300100];
    int main()
    {
        scanf("%d%d",&k,&n);
        if(k&1)
        {
            for(int i=1; i<=n; i++)
                a[i]=(k+1)/2;
            int last=n;//以下全是往前推n/2个序列的过程,last表示当前序列的最后一位!
            for(int i=1; i<=n/2; i++)
                if(a[last]==1) last--;
                else
                {
                    a[last]--;
                    for(int j=last+1; j<=n; j++)
                        a[j]=k;
                    last=n;
                }
            for(int i=1; i<=last; i++)
                printf("%d ",a[i]);
        }
        else
        {
            printf("%d ",k/2);
            for(int i=2; i<=n; i++)
                printf("%d ",k);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    PAT 甲级 1126 Eulerian Path (25 分)
    PAT 甲级 1126 Eulerian Path (25 分)
    PAT 甲级 1125 Chain the Ropes (25 分)
    PAT 甲级 1125 Chain the Ropes (25 分)
    PAT 甲级 1124 Raffle for Weibo Followers (20 分)
    PAT 甲级 1124 Raffle for Weibo Followers (20 分)
    PAT 甲级 1131 Subway Map (30 分)
    PAT 甲级 1131 Subway Map (30 分)
    AcWing 906. 区间分组 区间贪心
    AcWing 907. 区间覆盖 区间贪心
  • 原文地址:https://www.cnblogs.com/lglh/p/9447554.html
Copyright © 2011-2022 走看看