Finite Encyclopedia of Integer Sequences

本文介绍了一种算法,用于寻找特定条件下的字典序中间序列。该算法区分了偶数和奇数情况,并分别给出了相应的解决方案。

6617: Finite Encyclopedia of Integer Sequences

时间限制: 1 Sec  内存限制: 128 MB
提交: 379  解决: 92
[提交] [状态] [讨论版] [命题人: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.

题意 给你k和n,让你用1-k这些数字最长为n进行字典序排列,然后让你去中间的那个序列

思路:当k为偶数时最好弄,直接就是中间序列的最后一个就是k/2kkkkk,

如果k是奇数的话

让k/2排成一个n的序列然后就发现这个序列和答案所要的中间的序列差n/2个只要往前找n/2个

 

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[300005];
int main()
{
    ll k,n;
    cin>>k>>n;
 
    ll t=1;
    int i,j;
    if(k%2==0)
    {
 
        printf("%lld ",k/2);
        for(i=1; i<n; i++)
            printf("%lld ",k);
    }
    else
    {
        for(i=1; i<=n; i++)
            a[i]=(k+1)/2;
        int t=n;
        for(i=1; i<=n/2; i++)
        {
 
            if(a[t]==1) t--;
            else
            {
                a[t]--;
                for(j=t+1; j<=n; j++)
                    a[j]=k;
                t=n;
            }
        }
        for(i=1; i<=t; i++)
            printf("%d ",a[i]);
    }
 
 
 
}
 
 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值