题目描述

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 k …. k,共n个数。

k是奇数时,应该很靠近中间,即(k+1)/2 (k+1)/2 (k+1)/2…..正好相差n/2个字典序。让这个序列按照树的先序遍历往前退n/2步即为正确答案。

#include<bits/stdc++.h>
//int k,a[100010];
using namespace std;
const int INF=0x3f3f3f3f;
const int N=3e5+10;
int a[N];int Search(int *a,int key)
{ //在顺序表中折半查找key的数据元素。若找到,则函数值为
int low=0,mid; //该元素的数组下标;否则为0。
int high=14;
while(low <=high)
{
mid=(low+high)/2;
if(key==a[mid]) return mid; //找到待查元素
else if(key <a[mid]) high=mid-1; //继续在前半区间进行查找
else low=mid+1; //继续在后半区间进行查找
}}int main(){
int k,n;
scanf("%d%d",&k,&n);
if(k%2==0){printf("%d ",k/2);for(int i=2;i<=n;i++)printf("%d ",k);
}else {for(int i=1;i<=n;i++)a[i] = (k+1)/2;int t = n;for(int i=1;i<=n/2;i++)if(a[t]==1){t--;}else{a[t]--;while(t<n)a[++t]=k;}for(int i = 1; i <=t; i++)printf("%d ",a[i]);}return 0;
}

UPC 6617 Finite Encyclopedia of Integer Sequences(找规律)相关推荐

  1. upc 6617: Finite Encyclopedia of Integer Sequences(树的先序遍历第n/2个结点)

    6617: Finite Encyclopedia of Integer Sequences 时间限制: 1 Sec  内存限制: 128 MB 提交: 239  解决: 42 [提交] [状态] [ ...

  2. 6617: Finite Encyclopedia of Integer Sequences

    6617: Finite Encyclopedia of Integer Sequences 时间限制: 1 Sec  内存限制: 128 MB 提交: 341  解决: 75 [提交] [状态] [ ...

  3. UPC6617: Finite Encyclopedia of Integer Sequences

    6617: Finite Encyclopedia of Integer Sequences 时间限制: 1 Sec  内存限制: 128 MB 提交: 239  解决: 42 [提交] [状态] [ ...

  4. [ARC084]E - Finite Encyclopedia of Integer Sequences 乱搞

    题面 首先若k是偶数,答案显然是k/2,k,k,k-- 若k是奇数,我们考虑这样一个序列B:k/2,k/2,k/2--的排名. 构造一个映射f(X)->X',X是一个序列,X'是每个Xi替换成k ...

  5. 一个专门用来找规律的网站

    The On-Line Encyclopedia of Integer Sequences® (OEIS®)

  6. Yet Another Meme Problem(打表找规律)

    Try guessing the statement from this picture http://tiny.cc/ogyoiz. You are given two integers AA an ...

  7. 【HDU - 5881】Tea(思维,找规律)

    题干: Tea is good. Tea is life. Tea is everything. The balance of tea is a journey of pursuing balance ...

  8. *【CodeForces - 202C 】Clear Symmetry (思维,找规律,特判)

    题干: Consider some square matrix A with side n consisting of zeros and ones. There are nrows numbered ...

  9. 【CodeForces - 764A】Taymyr is calling you (找规律,水题)

    题干: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taym ...

最新文章

  1. 0x02.基本算法 — 递推与递归
  2. python提取excel中的某几列数据-python-将excel中的某些列读取到数据框
  3. iis php mysql 一键安装_LNMP(Nginx服务,MySQL 服务,安装PHP服务 手动安装技术文档)
  4. select multiple=multiple 数据回显
  5. 手写Spring-ioc 注入 jdk反射实现 绝对满足你的好奇心哦 解决怎么我写了一个注解就可以直接注入了?
  6. java timestamp时间差_关于datetime:如何在java中找到2个时间戳之间的日差
  7. linux环境下java开发_Linux Ubuntu系统下Java开发环境搭建
  8. 【thymeleaf】th:text、[[]]、th:utext、[()]输出变量
  9. 2006年4月计算机等级考试二级Java笔试答案
  10. Web前端开发工程师必读de设计博客
  11. php getdefaultvalue,PHP ReflectionParameter getDefaultValueConstantName()用法及代码示例
  12. 【Java】System.out.println(Integer.MAX_VALUE+1);背后的二进制故事与启示
  13. Spring中PropertyPlaceholderConfigurer的使用
  14. java三年技术差_3年经验Java程序员面阿里P6 差距在哪里
  15. Golang实现Server和Client的TCP通讯
  16. vant:修改van-nav-bar__title颜色——vant中nav-bar组件标题颜色
  17. ie6下margin间距是两倍的解决办法
  18. 【学习笔记】市场分析报告的基本框架
  19. WHYZOJ-#116[NOIP模拟] czy把妹(区间DP)
  20. [cf] Deltix Round, Autumn 2021 A. Divide and Multiply

热门文章

  1. 大数乘法——大数问题
  2. 平安科技王健宗:所有AI前沿技术,都能在联邦学习中大展身手
  3. Web全栈~10.流程控制
  4. 一文搞懂TCP/IP,入门计算机网络必看!
  5. 项目十大管理(六)人力资源管理
  6. python中的os.listdir()方法、os.path.isdir()方法
  7. Lock wait timeout exceeded; try restarting transaction
  8. 信而泰OLT使用介绍-网络测试仪实操
  9. python中int() 按照“四舍五入”的方式取整
  10. TP5.1自定义创建命令(php think make:controller app\index\User)