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

题意:给定一个数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. java核心知识点 --- 线程池ThreadPool

    线程池是多线程学习中需要重点掌握的. 系统启动一个新线程的成本是比较高的,因为它涉及与操作系统交互.在这种情形下,使用线程池可以很好的提高性能,尤其是当程序中需要创建大量生存期很短暂的线程时,更应该考 ...

  2. node-mysql中防止SQL注入

    备注: 本文针对mysqljs/mysql. 为了防止SQL注入,可以将SQL中传入参数进行编码,而不是直接进行字符串拼接.在node-mysql中,防止SQL注入的常用方法有以下四种: 方法一:使用 ...

  3. jmeter-plugins-dubbo & DevToolBox

    jmeter-plugins-dubbo使用 A. 下载jmeter并安装,http://jmeter.apache.org/download_jmeter.cgi(文中使用的版本是3.3,理论上高版 ...

  4. Python学习笔记_二维数组的查找判断

    在进行数据处理的工作中,有时只是通过一维的list和有一个Key,一个value组成的字典,仍无法满足使用,比如,有三列.或四列,个数由不太多. 举一个现实应用场景:学号.姓名.手机号,可以再加元素 ...

  5. 高性能python编程之协程(stackless)-乾颐堂

    我们都知道并发(不是并行)编程目前有四种方式,多进程,多线程,异步,和协程. 多进程编程在python中有类似C的os.fork,当然还有更高层封装的multiprocessing标准库,在之前写过的 ...

  6. Flask框架 之 第三方组件

    浏览目录 flask-session flask-sqlalchemy flask-script flask-migrate flask-session 安装 pip3 install flask-s ...

  7. 通过input上传图片,判断不同浏览器及图片类型和大小的js代码

    1.jsp页面代码 <form id="userPhoto" name="userPhoto" method="post" actio ...

  8. 03 Complementing a Strand of DNA

    Problem In DNA strings, symbols 'A' and 'T' are complements of each other, as are 'C' and 'G'. The r ...

  9. WireShark抓包的pcap文件格式分析

    http://www.360doc.com/content/14/0220/11/15257968_354157537.shtml http://www.360doc.com/content/14/0 ...

  10. 安装DotNetCore.1.0.0-VS2015Tools.Preview2一直失败

    266C:22B0][2016-08-01T23:02:29]i052: Condition 'WixBundleInstalled OR NOT(NetFx45Release < 378675 ...