CF1059C Sequence Transformation 题解
这几天不知道写点什么,状态也不太好,搬个题上来吧
题意:给定一个数n,设一个从1到n的序列,每次删掉一个序列中的数,求按字典序最大化的GCD序列
做法:按2的倍数找,但是如果除2能得到3的这种情况要特殊处理(¥#……%¥……@#¥不知道该怎么描述,看代码吧)
2 seconds
256 megabytes
standard input
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.
The first and only line of input contains one integer nn (1≤n≤1061≤n≤106).
Output nn integers — the lexicographically maximum result of the transformation.
3
1 1 3
2
1 2
1
1
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 题解的更多相关文章
- CF1059C Sequence Transformation
原题链接 题目大意 读入一个正整数\(n\).你有一个长度为\(n\)的排列.对于一次操作,我们需要做一下几步: 1.将目前序列内所有数的\(gcd\)加入答案中 2.将序列内随意删除一个数 3.如果 ...
- Codeforces Round #514 (Div. 2) C. Sequence Transformation(递归)
C. Sequence Transformation 题目链接:https://codeforces.com/contest/1059/problem/C 题意: 现在有1~n共n个数,然后执行下面操 ...
- 【CF 1059C】 Sequence Transformation 数学
C. Sequence Transformation:http://codeforces.com/contest/1059/problem/C 题意 给你一个n,第一次输出1-n个数的gcd,然后你可 ...
- [CodeForces]1059C Sequence Transformation
构造题. 我递归构造的,发现如果N>3的话就优先删奇数,然后就把删完的提取一个公约数2,再重复操作即可. 具体原因我觉得是因为对于一个长度大于3的序列,2的倍数总是最多,要令字典序最大,所以就把 ...
- Ural 1248 Sequence Sum 题解
目录 Ural 1248 Sequence Sum 题解 题意 题解 程序 Ural 1248 Sequence Sum 题解 题意 给定\(n\)个用科学计数法表示的实数\((10^{-100}\s ...
- CodeForces - 1059C Sequence Transformation (GCD相关)
Let's call the following process a transformation of a sequence of length nn. If the sequence is emp ...
- Lintcode388 Permutation Sequence solution 题解
[题目描述] Given n and k, return the k-th permutation sequence. Notice:n will be between 1 and 9 inclusi ...
- Codeforces Round #514 (Div. 2) C. Sequence Transformation 思维构造
题意 给出一个1-n的集合 gcd 集合里面的所有数 得到的 一个 数 然后自己选择删去一个数 要使得到的数 构成的数列 的字典序最大 思路: gcd所有数 那gcd得到的数肯定要小于数 ...
- Codeforces Round #514 (Div. 2) C. Sequence Transformation
题目大意:给你一个n 从1,2,3......n这个序列中 依次进行以下操作:1 .求所有数的最大公因数,放入a序列里面 2 .任意删去一个元素 一直到序列为空 根据删除元素的不同,导致序列a的字典序 ...
随机推荐
- Python基础:Python数据类型及逻辑判断语句
Python代码需要严谨的缩进 # 导包 import random # ********************输入输出***************** # 输出 print("hell ...
- 利用fetch进行POST传参
fetch(config.host+"url",{ method:"POST", mode: 'cors',跨域请求 headers: { ...
- 使用CMD命令行来对MySQL数据库执行迁移、备份、恢复
1. 导出数据库数据 "C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe" -u root -p123abc ...
- SQLSERVER 建立全文检索
-- 创建测试表 -- DROP TABLE FullTextIndexing CREATE TABLE FullTextIndexing ( ID INT IDENTITY(1,1) NOT N ...
- space defender,太空版植物大战僵尸 游戏基本框架的设计
- 关于使用PL/SQL连接本地oracle时报错:ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务解决
转自:https://blog.csdn.net/a657281084/article/details/49490069 问题:Oracle主服务和监听器服务已经启动,使用SQL Plus能够正常连接 ...
- Mysql设置auto_increment_increment和auto_increment_offset
查看与设置: show variables like '%auto_inc%'; show session variables like '%auto_inc%'; -- //session会话变量 ...
- Openssl verify命令
一.简介 verify命令对证书的有效性进行验证,verify 指令会沿着证书链一直向上验证,直到一个自签名的CA 二.语法 openssl verify [-CApath directory] [- ...
- Android 修改 TextView 的全局默认颜色。
如果你的应用中大多数TextView的颜色是红色, 或者其他颜色, 你是为每一个TextView都设置一次颜色, 还是有其他更好的办法, 这里教你怎么修改TextView的默认颜色. 当然我们Text ...
- 2015-08-13T17:39:15
ACTION里 Date upateTime; 有setter getter 页面字符串 是'2015-08-13T17:39:15' 该字符串可以直接映射成Date .