CodeForces 1059C
Description
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.
Sample Input
3
1 1 3
2
1 2
1
1
Sample Output
Hint
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.
尽可能的让大的gcd值尽快出现。
有一条规则可以推出来,两个连续的数的gcd是1,所以第一步是将原数列变成奇数数列或偶数数列,又因为对于长度n大于3时,偶数数列肯定要先出现大的gcd,所以第一步将原数列转成偶数数列。
之后有趣的事情就出现了,可以发现,可以将形成的数列,奇数位上的数看“奇数数列”,偶数位上的数看成“偶数数列”,又重复第一步的过程。
在以上整个程中n都是大于3的,对于小于3的直接按“偶奇奇”的顺序删。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp();
const int N = ; int con[]; int gcd(int a,int b)
{
int c;
while(b)
{
c=b;
b=a%b;
a=c;
}
return a;
} int main()
{
int i,p,j,n;
int cnt=;
scanf("%d",&n);
for(i=;i<=n;i++)
con[i]=i;
p=n;
while(p>)
{
if(p==)
{
printf("%d %d %d\n",gcd(gcd(con[],con[]),con[]),gcd(con[],con[]),con[]);
break;
}
else if(p>=)
{
cnt=;
int k=gcd(con[],con[]);
for(i=;i<=p;i+=)
{
printf("%d ",k);
if(i+<=p)
con[++cnt]=con[i+];
}
p=cnt;
}
else if(p==)
{
printf("%d\n",con[p]);
break;
} }
return ;
}
CodeForces 1059C的更多相关文章
- [CodeForces]1059C Sequence Transformation
构造题. 我递归构造的,发现如果N>3的话就优先删奇数,然后就把删完的提取一个公约数2,再重复操作即可. 具体原因我觉得是因为对于一个长度大于3的序列,2的倍数总是最多,要令字典序最大,所以就把 ...
- CodeForces - 1059C Sequence Transformation (GCD相关)
Let's call the following process a transformation of a sequence of length nn. If the sequence is emp ...
- codeforces 1059C. Sequence Transformation【构造】
题目:戳这里 题意:有1,2,3...n这n个数,求一次这些数的gcd,删去一个数,直到剩下一个数为止.输出这n个gcd的最大字典序. 解题思路:一开始的gcd肯定是1,要让字典序最大,我们可以想到下 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- 本科毕业平均年薪 30 万!经济寒冬挡不住 AI 人才的火热!
互联网行业遭遇寒冬,企业纷纷裁员缩招,而 BAT 和硅谷明星公司对 AI 人才的投入却并不见放缓.为争夺相关人才,给应届毕业生开出的平均年薪高达 30 万. 而 TensorFlow 作为当下最流行的 ...
- EOS开发基础之二:使用cleos命令行客户端操作EOS(钱包wallet基础操作)
不知道下边这一段英文你们是不是能看懂,如果看不懂那就算了,我就是转过来随便看看的. 总之你记住nodeos.cleos和keosd这三个工程十分重要就行了,回头咱们的研究都从这三个工程杀进去. EOS ...
- 了不起的Node.js--之五 TCP连接
TCP连接 传输控制协议(TCP)是一个面向连接的协议,它保证了两台计算机之间数据传输的可靠性和顺序. TCP是一种传输层协议,它可以让你将数据从一台计算机完整有序地传输到另一台计算机. Node.j ...
- symfon2 配置文件使用 + HttpRequest使用 + Global多语言解决方案
1. 在 app/conig中建立一个自命名的文件: abc.yml 2. 在 app/config/config.yml中导入abc.yml 文件头部: imports:- { resource: ...
- PHP Laravel Install and Quickstart
1.安装Laravel 一键安装包Laravel 要安装Laravel依赖的PHP7以上版本,以及php 扩展php-openssl php-pdo ... 以及Homestead github下载安 ...
- Notes of Daily Scrum Meeting(12.3)
这个月大家的课业任务很重啊,加上软工有三个课程设计要完成了,感觉亚历山大的说,而且我们alpha阶段完成度低一些, 所以任务更多了,今天做的东西就不多,希望大家加油吧! 团队成员 今日团队工作 陈少杰 ...
- Spark 实践——用决策树算法预测森林植被
本文基于<Spark 高级数据分析>第4章 用决策树算法预测森林植被集. 完整代码见 https://github.com/libaoquan95/aasPractice/tree/mas ...
- 刚做了个实验,验证++和!和printf的先后次序
- Beta阶段敏捷冲刺总结
设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 在最开始的时候我们就是为了解决集美大学计算机工程学院网页没有搜索引擎的问题.因为没有搜 ...
- 【设计模式】—— 观察者模式Observer
前言:[模式总览]——————————by xingoo 模式意图 观察者模式,也叫发布/订阅模式,从名字来说就能察觉到它的过程应该是,发布——其他人接受. 这个模式定义了对象之间的一种依赖关系,当一 ...