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的字典序 ...
随机推荐
- xbstream 备份恢复
xbstream -x < ./backs/backup.xbstream -C /dbnode/data/ innobackupex --defaults-file=/dbnode/etc/ ...
- 使用jQuery解析JSON数据-已验证
本文来源于:http://www.cnblogs.com/codeplus/archive/2011/07/18/2109544.html 上例中得到的JSON数据如下,是一个嵌套JSON: {&qu ...
- selenium+jenkins网页自动化测试的构建
jenkins+selenium可以做到对web自动化的持续集成. Jenkins的基本操作: 一.新建视图及job 新建视图: 新建job: 可以选择构建一个自由风格的软件项目或者复制已有的item ...
- @EnableAsync annotation metadata was not injected Spring容器启动后访问Servlet报错
@EnableAsync annotation metadata was not injected 2015年12月20日 20:06:54 7570 在初始化spring事务部分碰到该错误, 详细错 ...
- CS的项目管理是基于多租户理念设计
1.创建项目 http://xxx.xxx.xx.xx:8080/client/api?command=createProject&response=json&sessionkey=8 ...
- [C++] Const Summary (mind map)
Const Summary
- Java 读取jar内的文件的超简便方法
坑爹的java课程设计,偏要用jar来运行 读取.存储jar内文件的支持也好低 存储方法: 进入jar文件其实没有说的那么困难,jar文件本质是一个zip格式的压缩文件,只是把文件后缀名改了,要用Ja ...
- OpenCV实现pHash哈希
离散余弦变换(DCT,Discrete Cosine Transform)是与傅里叶变换相关的一种变换,它类似于离散傅里叶变换(DFT,Discrete Fourier Transform),但是只使 ...
- jmeter- 性能测试3:聚合报告(Aggregate Report )
jmeter-监听器-聚合报告样例: 字段说明: label:请求名称,自己定义的 #Samples:这次测试中一共发出了多少个请求,如果模拟20个用户,每个用户迭代20次,那么就是400(未设置持续 ...
- java学习(二)运算符
一.运算符 赋值运算符:= += -= *= /= %= 算术运算符:+ - * / % ++ -- int x = 3; int y = 4 int c = x*1.0 ...