码迷,mamicode.com
首页 > 其他好文 > 详细

Finite Encyclopedia of Integer Sequences

时间:2018-08-04 17:29:25      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:规律   分享   需要   技术   分享图片   ogr   bsp   hose   输出   

题目描述

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

需要找出规律

当k为偶数时,输出k/2,k, k...共n项

当k为奇数时,算了,上官方的吧,我也写不出来了...

技术分享图片

然后我也编了一组数据,从(1,3,3)倒着带入程序就好理解le

.....(1,1,1)   (1,1,2)  (1,1,3)(1,2,1)(1,2,2)  (1,2,3)  (1,3,1)  (1,3,2)  (1,3,3)

#include<bits/stdc++.h>
using namespace std;
const int m = 1e5;
typedef long long ll;
ll a[3*m+5];
int main()
{
    int k,n;
    cin>>k>>n;
    if(k%2==0)
    {
        cout<<k/2<<" ";
        for(int i = 2; i <= n; i++)
        cout<<k<<" ";
    }
    else
    {
        for(int i = 1; i <= n; i++)
        a[i] = (k+1)/2;
        int len = n;
        for(int i = 1; i <=  n/2; i++)  //模拟 ,模拟次数找规律 
        {
            if(a[len] == 1)    len--;
            else
            {
                for(int j = len+1; j <= n; j++)
                a[j] = k;  
                a[len]--;
                len = n; 
            }
        }
        for(int i = 1; i <= len; i++)
        cout<<a[i]<<" ";
    }
    return 0;
}

好吧,终于写完了,hhhhaaa,有错误望指出Ooooooo

 

Finite Encyclopedia of Integer Sequences

标签:规律   分享   需要   技术   分享图片   ogr   bsp   hose   输出   

原文地址:https://www.cnblogs.com/lwsh123k/p/9419087.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!