C. Sequence Transformation

探讨了一种序列转换过程,通过删除元素并记录每次删除前的序列最大公约数,最终得到字典序最大的结果序列。文章提供了一个算法,用于解决给定长度序列的最优转换策略,并附带代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

滴答滴答---题目链接 

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.

考虑规模为 kk 的一个问题:11 ~ kk 的一个排列,求字典序最大的答案序列。

当 k\le 3k≤3 时,就是样例;当 k>3k>3 时,为了使答案序列的字典序尽量大,需要删尽量少的数使得 gcd\neq 1gcd≠1,此时删掉所有奇数一定是最优的,因为对于任意的 k>3,x>2k>3,x>2 有 \small\left\lfloor\dfrac{k}{x}\right\rfloor<\left\lfloor\dfrac{k}{2}\right\rfloor⌊xk​⌋<⌊2k​⌋。删掉所有奇数后,剩下的数为都为 22 的倍数(废话...),那么如果将所有数除以二,最优的删数方案是不会变的,而此时剩余的问题被转化成了一个规模为 \small\left\lfloor\dfrac{k}{2}\right\rfloor⌊2k​⌋ 的原问题,输出答案时将答案乘二即可。

换句话说,令 T(k)T(k) 为 1,2,3,\cdots,k1,2,3,⋯,k 这个序列的字典序最大的答案序列,那么:\begin{cases}T(k)=\{1\}\quad(k=1)\\T(k)=\{1,2\}\quad(k=2)\\T(k)=\{1,1,3\}\quad(k=3)\\T(k)=\{1,1,\cdots,1\}(\small\text{共}\left\lceil\dfrac{k}{2}\right\rceil\text{个 1})\normalsize+T\left(\small\left\lfloor\dfrac{k}{2}\right\rfloor\right)\text{的每一项乘二}\normalsize\quad(k>3)\end{cases}⎩⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎧​T(k)={1}(k=1)T(k)={1,2}(k=2)T(k)={1,1,3}(k=3)T(k)={1,1,⋯,1}(共⌈2k​⌉个 1)+T(⌊2k​⌋)的每一项乘二(k>3)​

实现时并不需要递归地实现,详见代码:

#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int n,j;
    cin>>n;
    int qaq=1;
    while(n>=4)
    {
        for(int i=0; i<(n+1)/2; i++)
            printf("%d ",qaq);
        n/=2;
        qaq*=2;
    }
    if(n==3)
        printf("%d %d %d\n",qaq,qaq,qaq*3);
    else if(n==2)
        printf("%d %d\n",qaq,qaq*2);
    else printf("%d\n",qaq);

    return 0;
}

 

<think>我们正在解决CloudCompare中将点云数据的树冠朝向从Y轴改为Z轴的问题,重点在于找到并正确使用"永久变换(Permanenttransformation)"功能。根据之前的讨论,我们知道:-需要应用一个变换矩阵来交换Y和Z坐标(即用矩阵将点(x,y,z)变为(x,z,y))-在应用变换矩阵时,必须勾选“Permanenttransformation”选项,这样才能修改原始数据,而不是只改变显示。现在,用户明确询问“永久变换”功能的位置以及具体操作步骤。操作步骤:1.打开点云文件后,选中需要变换的点云对象(在DB树中单击选中)。2.点击顶部菜单栏的“Tools”菜单。3.在下拉菜单中选择“Transformation”->“Applytransformationmatrix...”。4.在弹出的对话框中,输入变换矩阵(4x4矩阵):第一行:1,0,0,0第二行:0,0,1,0[这行表示新的Y坐标等于原来的Z坐标]第三行:0,1,0,0[这行表示新的Z坐标等于原来的Y坐标]第四行:0,0,0,15.在对话框的下方,找到“Permanenttransformation”复选框,并勾选它。6.点击“Apply”按钮应用变换,此时点云的原始数据将被永久修改(注意:原数据会被替换,建议先保存副本)。7.应用后,在DB树中会出现一个新的点云对象(名称可能带有[Transformed]前缀),而原始对象会被隐藏(或替换)。实际上,由于我们选择了永久变换,原始数据已经被修改,但CloudCompare会创建一个新的实体来显示变换后的结果,原始实体则被标记为隐藏(通常名称前会有一个小眼睛图标且关闭)。注意:应用变换后,为了确保数据已经更新,可以右键点击变换后的点云,选择“Tools”->“Listpoints”查看前几个点的坐标,确认Y和Z已经交换。保存变换后的点云:-在DB树中选中变换后的点云(即[Transformed]开头的那个),右键选择“Save”...。-在保存对话框中,选择适当的格式(如PLY、LAS等),注意不要勾选“Saveglobalshift”(除非你的数据有全局偏移),并确保勾选“Applytransformation”(如果存在)以将变换应用到保存的数据中(实际上,由于我们已经是永久变换,点坐标已经改变,所以保存时直接保存即可)。重要提示:永久变换会直接修改点云的坐标数据,且不可撤销(除非你关闭文件而不保存)。因此,在进行永久变换前,建议先保存原始数据的备份。如果用户需要更详细的操作截图或视频,可以建议参考CloudCompare官方文档或教程。下面,我们将按照要求组织回答。</think>### CloudCompare永久变换功能位置与Y/Z轴变换指南 在CloudCompare中实现树冠朝向从Y轴改为Z轴的核心操作是**永久变换(Permanent transformation)**,以下是详细操作流程: #### 一、永久变换功能位置与启用步骤 1. **菜单路径**: ``` 主菜单 → Tools → Transformation → Apply transformation matrix ``` 2. **关键操作界面**: ```mermaid graph TD A[打开变换矩阵对话框] --> B[输入4×4变换矩阵] B --> C{勾选关键选项} C --> D[点击Apply] ``` 在对话框中**必须勾选**: - ✅ `Permanent transformation`(永久变换) - ✅ `Update display`(实时更新显示) #### 二、Y轴转Z轴的变换矩阵配置 用于交换Y/Z坐标的变换矩阵为: $$M = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}$$ **矩阵输入示例**: ``` 1 0 0 0 // X保持不变 0 0 1 0 // 新Y = 原Z 0 1 0 0 // 新Z = 原Y 0 0 0 1 // 齐次坐标 ``` #### 三、验证与保存流程 1. **验证变换结果**: - 右键变换后的点云 → `Tools > List points` - 检查坐标是否变为$(x, z, y)$格式 2. **正确保存姿势**: - 在DB树中选择`[Transformed]`前缀的新实体 - 保存时取消勾选`Save global shift` - 推荐使用LAS/PLY格式(避免数据丢失) #### 四、常见问题排查 | 现象 | 解决方案 | |------|----------| | 保存后数据未更新 | 检查是否选中`[Transformed]`实体[^1] | | 坐标值未改变 | 确认已勾选`Permanent transformation` | | 文件打开异常 | 改用LAS格式保存[^2] | > ⚠️ **重要提示**:永久变换会直接修改原始数据,操作前建议通过`File > Save as`备份原始点云。 #### 五、操作演示(树冠朝向修正) ```mermaid sequenceDiagram 用户->>CloudCompare: 加载树点云(树冠朝Y) CloudCompare->>用户: 显示初始朝向 用户->>变换矩阵对话框: 输入Y/Z交换矩阵 用户->>选项框: 勾选Permanent transformation CloudCompare->>点云: 应用永久变换 点云->>用户: 生成[Transformed]实体 用户->>文件菜单: 保存新实体为LAS ``` 通过此流程,树冠将精确地从Y轴转向Z轴,且变换结果会持久化保存在文件中[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值