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.

 

样例输入

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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值