UPC6617: Finite Encyclopedia of Integer Sequences

6617: Finite Encyclopedia of Integer Sequences

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

样例输入

扫描二维码关注公众号,回复: 2628007 查看本文章
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 

题意:给你个k和一个n,现在要组成序列,k表示能用1-k的数字,n表示序列的长度可以是1-n。如:k=3,n=2,则可以组成的序列是(1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3)共12个,设总数有X个,问你按照字典序排序第X/2个是那个序列。

小结:规律题要耐心去找,慢慢试总会有收获的。

思路:这题有点幸运。。写上几组示例后发现:

k为偶数的时候答案就是k/2,k,k........

k为奇数时候写了多组然后各种瞎猜后竟然发现就是(k+1)/2,(k+1)/2,(k+1)/2......往前移动n/2个...当然也不能全靠猜,总感觉可能跟中间那个值有关于是竟然真的有关。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define FIN freopen("D://code//in.txt", "r", stdin)
#define ppr(i,x,n) for(int i = x;i <= n;i++)
#define rpp(i,n,x) for(int i = n;i >= x;i--)
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

inline int read() {//读入挂
    int ret = 0, c, f = 1;
    for(c = getchar(); !(isdigit(c) || c == '-'); c = getchar());
    if(c == '-') f = -1, c = getchar();
    for(; isdigit(c); c = getchar()) ret = ret * 10 + c - '0';
    if(f < 0) ret = -ret;
    return ret;
}
ll a[maxn];
int main()
{
	IO;
	ll k,n;
	cin>>k>>n;
	if(k%2 == 0)
	{
		ppr(i,1,n)
		{
			if(i == 1)
			printf("%lld ",k/2);
			else
			printf("%lld%c",k,i==n?'\n':' ');
		}
	}
	else
	{
		ll number = (k+1)/2;
		ll num = n;
		ppr(i,1,n) a[i]=number;
		ppr(i,1,n/2)
		{
			if(a[num] == 1)
			{
				a[num] = k;
				num--;
			}
			else
			{
				a[num]--;
				num = n;
			}
		}
		ppr(i,1,num)
		{
			printf("%lld%c",a[i],i==num?'\n':' ');
		}
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Pandapan1997/article/details/81393090
今日推荐