这几天不知道写点什么,状态也不太好,搬个题上来吧

题意:给定一个数n,设一个从1到n的序列,每次删掉一个序列中的数,求按字典序最大化的GCD序列

做法:按2的倍数找,但是如果除2能得到3的这种情况要特殊处理(¥#……%¥……@#¥不知道该怎么描述,看代码吧)

C. Sequence Transformation
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Let's call the following process a transformation of a sequence of length nn.

If the sequence is empty, the process ends. Otherwise, append the greatest common divisor (GCD) of all the elements of the sequence to the result and remove one arbitrary element from the sequence. Thus, when the process ends, we have a sequence of nn integers: the greatest common divisors of all the elements in the sequence before each deletion.

You are given an integer sequence 1,2,…,n1,2,…,n. Find the lexicographically maximum result of its transformation.

A sequence a1,a2,…,ana1,a2,…,an is lexicographically larger than a sequence b1,b2,…,bnb1,b2,…,bn, if there is an index ii such that aj=bjaj=bj for all j<ij<i, and ai>biai>bi.

Input

The first and only line of input contains one integer nn (1≤n≤1061≤n≤106).

Output

Output nn integers  — the lexicographically maximum result of the transformation.

Examples
input

Copy
3
output

Copy
1 1 3 
input

Copy
2
output

Copy
1 2 
input

Copy
1
output

Copy
1 
Note

In the first sample the answer may be achieved this way:

  • Append GCD(1,2,3)=1(1,2,3)=1, remove 22.
  • Append GCD(1,3)=1(1,3)=1, remove 11.
  • Append GCD(3)=3(3)=3, remove 33.

We get the sequence [1,1,3][1,1,3] as the result.

 #include <iostream>
using namespace std; int p[]; int _pow(int a, int b)
{
int ans = ;
int temp = a;
while (b)
{
if (b & )
ans *= temp;
temp *= temp;
b >>= ;
}
return ans;
} int main()
{
ios::sync_with_stdio(false);
cout.tie();
for (int i = ; i <= ; i++)
{
p[i] = _pow(, i);
} int n;
cin >> n;
if (n == )
{
cout << "1 1 3" << endl;
return ;
} int step = ;
int flag = ;
int n1 = n;
while (n1)
{
if (n1 == && !flag)
{
int temp = ;
while (temp <= n)
{
temp *= ;
}
flag = temp / ;
break;
}
n1 /= ;
}
while (n)
{
int num = n - n / ;
n -= num; for (int i = ; i < num; i++)
{
if (flag && num == )
cout << flag;
else
cout << p[step];
if (i != num - || n)
cout << " ";
}
step++;
} cout << endl;
return ;
}

CF1059C Sequence Transformation 题解的更多相关文章

  1. CF1059C Sequence Transformation

    原题链接 题目大意 读入一个正整数\(n\).你有一个长度为\(n\)的排列.对于一次操作,我们需要做一下几步: 1.将目前序列内所有数的\(gcd\)加入答案中 2.将序列内随意删除一个数 3.如果 ...

  2. Codeforces Round #514 (Div. 2) C. Sequence Transformation(递归)

    C. Sequence Transformation 题目链接:https://codeforces.com/contest/1059/problem/C 题意: 现在有1~n共n个数,然后执行下面操 ...

  3. 【CF 1059C】 Sequence Transformation 数学

    C. Sequence Transformation:http://codeforces.com/contest/1059/problem/C 题意 给你一个n,第一次输出1-n个数的gcd,然后你可 ...

  4. [CodeForces]1059C Sequence Transformation

    构造题. 我递归构造的,发现如果N>3的话就优先删奇数,然后就把删完的提取一个公约数2,再重复操作即可. 具体原因我觉得是因为对于一个长度大于3的序列,2的倍数总是最多,要令字典序最大,所以就把 ...

  5. Ural 1248 Sequence Sum 题解

    目录 Ural 1248 Sequence Sum 题解 题意 题解 程序 Ural 1248 Sequence Sum 题解 题意 给定\(n\)个用科学计数法表示的实数\((10^{-100}\s ...

  6. CodeForces - 1059C Sequence Transformation (GCD相关)

    Let's call the following process a transformation of a sequence of length nn. If the sequence is emp ...

  7. Lintcode388 Permutation Sequence solution 题解

    [题目描述] Given n and k, return the k-th permutation sequence. Notice:n will be between 1 and 9 inclusi ...

  8. Codeforces Round #514 (Div. 2) C. Sequence Transformation 思维构造

    题意 给出一个1-n的集合   gcd 集合里面的所有数  得到的 一个 数   然后自己选择删去一个数   要使得到的数 构成的数列 的字典序最大 思路: gcd所有数 那gcd得到的数肯定要小于数 ...

  9. Codeforces Round #514 (Div. 2) C. Sequence Transformation

    题目大意:给你一个n 从1,2,3......n这个序列中 依次进行以下操作:1 .求所有数的最大公因数,放入a序列里面 2 .任意删去一个元素 一直到序列为空 根据删除元素的不同,导致序列a的字典序 ...

随机推荐

  1. JsSIP 注册,拨打填坑

    吐个槽: http://tryit.jssip.net/  这个毛东西,默认是要使用视频的,而且没得设置不使用,至少我没看到有设置的!!!(其实就是写死了,翻了他的js代码的-_-||) 设置连接到自 ...

  2. 147. Insertion Sort List (List)

    Sort a linked list using insertion sort. class Solution { public: ListNode *insertionSortList(ListNo ...

  3. Python之多进程和多线程

    目标: 1.os.fork简单示例 2.使用os.fork多进程测试IP是否在线 3.使用os.fork多进程解决tcpserver多客户端连接问题 4.多线程测试IP地址是否在线 1.os.fork ...

  4. LVS集群中实现的三种IP负载均衡技术

    LVS有三种IP负载均衡技术:VS/NAT,VS/DR,VS/TUN. VS/NAT的体系结构如图所示.在一组服务器前有一个调度器,它们是通过Switch/HUB相连接的.这些服务器 提供相同的网络服 ...

  5. hash+链表

    简单的hash就是用数组加链表的组合来实现,这种hash很简单,但hash的思想在那. #ifndef _HASH_H_ #define _HASH_H_ typedef struct _ListNo ...

  6. 安装运行 rovio odometry

    https://github.com/ethz-asl/rovio https://github.com/ethz-asl/kindr 1. 新建catkinworkspace mkdir -p ~/ ...

  7. Spring.net方法的替换

    .为什么有时候你再执行某个方法的时候比如某个操作 a.权限验证 b.任务执行 当我执行到这个方法的时候,我可以先验证权限,如果验证不通过则替换到另一个方法去执行 public class MyValu ...

  8. mysql varchar 类型 超出字符

    4.0版本以下,varchar(50),指的是50字节,如果存放UTF8汉字时,只能存16个(每个汉字3字节) 5.0版本以上,varchar(50),指的是50字符,无论存放的是数字.字母还是UTF ...

  9. 白盒测试实践项目(day4)

    华中科技大学教材订购系统 代码评审会议纪要 与会人员: 胡俊辉.杨瑞丰.汪鸿.张颖.李建文 评审标准: 此次代码评审会议,我们小组选用了阿里巴巴Java开发手册对代码进行评审. 会议过程: 1:周末下 ...

  10. js流程图:aworkflow.js

    auto-workflow 用于快速构建各种关系图的库 github地址:https://github.com/auto-workflow/AWorkflow 快速开始 npm install awo ...