[CodeForces]1059C Sequence Transformation

构造题。

我递归构造的,发现如果N>3的话就优先删奇数,然后就把删完的提取一个公约数2,再重复操作即可。

具体原因我觉得是因为对于一个长度大于3的序列,2的倍数总是最多,要令字典序最大,所以就把非2的倍数全删了。

假设不删奇数,剩下的数要提取出来非1的公因数,要删的数一定比删奇数删的起码多1,出现比之前的公因数大的质因数的位置就会往后推,这样字典序就小了。

#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int n;
void print(int sz,int tp) {
    if(sz==3) {printf("%d %d %d",tp,tp,tp*3);return;}
    if(sz==2) {printf("%d %d",tp,tp*2);return;}
    if(sz==1) {printf("%d",tp);return;}
    for(int i=1;i<=sz-(sz>>1);i++) printf("%d ",tp);
    print((sz>>1),tp<<1);      
    
}
int main() {
    scanf("%d",&n);
    print(n,1);
}                                            
Sequence Transformation
我是咸鱼。转载博客请征得博主同意Orz
原文地址:https://www.cnblogs.com/sdfzhsz/p/9746558.html