Codeforces 977D. Divide by three, multiply by two

Silvaco TCAD | GaN HEMT器件仿真与高频功率应用实战 本文详细介绍了使用Silvaco TCAD进行GaN HEMT器件仿真的全流程,涵盖器件结构设计、极化效应建模、高频特性分析及功率损耗优化。通过实战案例展示了GaN HEMT在电动汽车电驱和快充模块等高频功率应用中的性能优势与效率提升策略,为工程师提供可靠的仿真方法与设计验证手段。 阅读详情

Divide by three, multiply by two

Polycarp likes to play with numbers. He takes some integer number x, writes it down on the board, and then performs with it n−1 operations of the two kinds:

divide the number x by 3 (x must be divisible by 3);
multiply the number x by 2.
After each operation, Polycarp writes down the result on the board and replaces x by the result. So there will be n numbers on the board after all.

You are given a sequence of length n — the numbers that Polycarp wrote down. This sequence is given in arbitrary order, i.e. the order of the sequence can mismatch the order of the numbers written on the board.

Your problem is to rearrange (reorder) elements of this sequence in such a way that it can match possible Polycarp’s game in the order of the numbers written on the board. I.e. each next number will be exactly two times of the previous number or exactly one third of previous number.

It is guaranteed that the answer exists.

Input

The first line of the input contatins an integer number n (2≤n≤100) — the number of the elements in the sequence. The second line of the input contains n integer numbers a1,a2,…,an (1≤ai≤3⋅1018) — rearranged (reordered) sequence that Polycarp can wrote down on the board.

Output

Print n integer numbers — rearranged (reordered) input sequence that can be the sequence that Polycarp could write down on the board.

It is guaranteed that the answer exists.

Examples

input

6
4 8 6 3 12 9

output

9 3 6 12 4 8

input

4
42 28 84 126

output

126 42 84 28

input

2
1000000000000000000 3000000000000000000

output

3000000000000000000 1000000000000000000

Note

In the first example the given sequence can be rearranged in the following way: [9,3,6,12,4,8]. It can match possible Polycarp’s game which started with x=9.


题意:
给你一组数,这组数是由一个数经过除以三,乘以二变化来的,这个数也给了
让你输出变化的顺序
如给的是4 8 6 3 12 9
那么答案就是 9 3 6 12 4 8
结果一定是唯一的

这道题,脑袋不知道怎么了,周赛的时候做没有做出来,。,,
回头补了一下,发现不是很难
由于n比较小,
第一种方式我采用的是暴力建链表
对于任意两个数a b
如果 a * 3 == b || a = b * 2
那么就说明,在生成的序列中 a 在 b 的前面


//暴力建立链表 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


ll a[128];
int l[128];
bool f[128];
int main()
{
	int n;
	cin>>n;
	memset(f,0,sizeof(f));
	memset(l,-1,sizeof(l));
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			if(i==j)	continue;
			if(a[i]*2==a[j]||a[i]==a[j]*3)	l[i]=j,f[j]=1;// a[i] 在前,a[j]在后 没有被用过的是头节点 
		}
	int t = -1;
	for(int i=0;i<n;i++)
		if(!f[i])
		{
			t = i;
			break;
		}
	for(t;~t;t=l[t])
		printf("%I64d%c",a[t]," \n"[t==-1]);
	return 0;
}

第二种方法是:
我们经过观察到结果序列规律:
能整除3的次数越多,优先级越高,次数相同的按照从小到大排列

于是我用pair<int,long long> 来存数,第一个存优先级,第二个存数
对pair进行sort的时候,会自动按照first从小到大排序,first相等时按照second从小到大排序


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 107;
ll a[MAXN];
ll f(ll x)
{
	ll ans = 0;
	while(x%3==0)
	{
		x/=3;
		ans++;
	}
	return ans;
}
int main()
{
	int n;
	cin>>n;
	vector<pair<int,ll> > v;
	v.resize(n);
	for(int i=0;i<n;i++)
	{
		scanf("%I64d",&v[i].second);
		v[i].first = -f(v[i].second); 
	}
	sort(v.begin(),v.end());//pair<> 数组的性质,先按first从小到大排序,first相等时按照second从小到大排序 
	for(int i=0;i<n;++i)
		printf("%I64d%c",v[i].second," \n"[i==n-1]); 
	return 0;
}

DELPHI11 利用Android手机实现条码扫描功能 好了,整个过程全部结束,当然这只是最简单的例子,只是演示一下如何识别条码,更多的条码处理功能,比如优化,提速等需要在后面继续。安装过程中所有提示框全部按OK就可以,直到提示安装成功,那么ZXing库就成功完成了安装。点击红框标识的文件夹图标,将下载的ZXing库文件路径加入进来后,点ADD。第三步:选择下载的ZXing库路径,并按Ctrl + A进行全选,并导入。至此为止,我们的库才算是全部安装完成,可以在DELPHI 中正常引用了。2.打开相机,识别条码,并将条码内容显示在MEMO1中。 阅读详情

相关推荐

3台虚拟机部署Doris详细文档(含校验步骤)

摘要:本文详细介绍了Apache Doris在3台虚拟机上的集群部署方案。采用1主FE+1从FE+1观察者FE+3BE的混合部署模式,确保元数据高可用性。硬件配置建议测试环境4核16GB内存,生产环境8核64GB内存。部署步骤包括系统环境配置(关闭防火墙、内核参数优化)、FE/BE节点配置启动、集群初始化验证等。重点配置了IP白名单(172.30.0.115)和数据目录(/data/doris)。通过MySQL客户端和WebUI可监控集群状态,实现千万级数据的实时分析能力,后续可通过增加BE节点线性扩展。

weixin_41026747的博客 933

Codeforces977 D. Divide by three, multiply by two(思维、质因子)

题意: 给定长度为n的序列a 要求重新排列序列,使得序列满足a(i+1)=2*a(i)或a(i+1)=a(i)/3 即后一个数是前一个数的两倍或者三分之一 保证一定有解 数据范围:n<=100 解法: 1.看到dfs的解法 2.看到拓扑排序的解法(需要证明直接建图不存在环) 3.看到从质因子方向考虑的解法: 乘2可以看成添加一个质因子2,除3可以看成去掉一个质因子3 因为质因子3的个数决定了后面能有多少个除以3的,所以质因子3最多的数一定在最前面 如果有质因子3数量相同的数,因为乘2会变大,为了使得序

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 292

SBM与超效率SBM模型实战:从原始面板数据到MATLAB高效实现

本文详细介绍了SBM模型与超效率SBM模型的核心原理,并提供了从原始面板数据预处理到MATLAB高效实现的完整实战指南。通过具体代码解析,帮助研究者掌握如何利用MATLAB进行数据标准化、模型构建、效率求解及结果可视化,从而精准评估决策单元的相对效率,尤其适用于在高效单元中进一步精细排名的场景。

weixin_29100399的博客 479

Codeforces 977D 题解报告

一、题目 http://codeforces.com/contest/977/problem/D 二、分析 依题意,可以考虑一个数是3的多少次幂,可以有余数。 比如18是3的2次幂,余数为2; 9是3的2次幂,余数为0; 2是3的0次幂,余数为2。 首先要把幂从高到低的顺序排列,比如9(3的2次幂)必然排在3(3的1次幂)的前面。 对于同一次幂,要按从小到大的顺序排序,这样后面...

小树学信奥 524

本地部署大模型 vs 网页版大模型区别

fill:#333;color:#333;color:#333;fill:none;本地服务器/工作站硬件资源私有化部署GPU集群高速存储模型文件训练框架推理引擎。

Ds-Rag的博 1712

STM32F103模拟SSI时序解析:实现高精度绝对式编码器位置读取

本文详细解析了如何在STM32F103微控制器上通过软件模拟SSI协议时序,实现高精度绝对式编码器的位置读取。文章从项目驱动出发,深入剖析了SSI通信原理、硬件电平转换连接、核心软件模拟代码实现及关键时序参数调试方法,并提供了使用示波器进行波形对齐与优化的实战指南,为成本敏感型工业控制与机器人项目提供了高性价比的解决方案。

weixin_29196315的博客 141

Codeforces 977D(思维)

传送门题面:D. Divide by three, multiply by twotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp likes to play with numbers. He takes some integer...

Chen.Jr的博客 1056

深入浅出DNS系列(一)- DNS杂谈

黄丝玛:班达山,你好,我记性不好,你告诉我搜狐、新浪的网站IP地址好吗? 班达山:你问问DNS先生吧,他专门干这买卖的

jiangsd198的博客 4129

Codeforces977D ---Divide by three, multiply by two 深搜+map存出现的数

传送门:点我 题意:给定n长度的序列,重排成后一个数是前一个数除以三,或者后一个数是前一个数乘二,要求输出这个序列。 思路:大力深搜,对每个数搜除3的和乘2的是否出现过,然后继续搜下去。如果有一个数搜能搜完整个序列,那就输出这个数开始的一整个序列。 代码: #include<bits/stdc++.h> using namespace std; typedef uns...

weixin_30480583的博客 158

three.js 载入 3D 模型的方法

三维模型的加载器ColladaLoader模型加载器。GLTFLoader模型加载器。OBJLoader模型加载器。FBXLoader模型加载器。

w418856的博客 4362

vue2 - 实现移动端H5网页调用手机相册选取图片或打开摄像头相机拍照上传,如何在h5网站浏览器中打开本机相册或相机选择相片,H5调用本地相册/相机上传图片详细教程(附图片压缩功能及上传服务器示例)

vue2手机H5网页,调起安卓苹果ios手机相册和相机,H5实现调用手机摄像头相册实现图片压缩预览删除,vue项目调用摄像头和相册,H5调用手机摄像头,实时拍照上传,VUE2 H5页面如何唤起手机摄像头拍照上传,H5调起手机端的摄像头,html5调用手机摄像头,实现H5调起手机相机和相册,vue H5拍照上传,手机网站浏览器移动端调取相机或相册,实现拍照上传功能,解决苹果ios手机无法打开相册相机问题,无法唤起摄像头怎么办,调取本机系统的相册,vue h5网页调用相机拍照和相册,实现多张图片上传功能,图片压

✅ 精选推荐文章 1万+

codeforces 977D Divide by three, multiply by two

D. Divide by three, multiply by twotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp likes to play with numbers. He takes some integer numbe...

shyoldman的博客 749

【YOLOv26 源码深度解析】第三章:YOLOv26特征融合(Neck)模块

路径聚合网络作为YOLOv26 Neck部分的核心组件,在继承特征金字塔网络(FPN)自顶向下语义传播能力的基础上,引入了自底向上的路径增强机制,构建起双向跨层特征融合体系。该架构通过建立多尺度特征间的双向信息流,有效缓解了深层网络中细节信息逐层衰减的问题,使得模型在保持高层语义理解能力的同时,能够精确定位不同尺度的目标实例。跨层深度监督的另一优势在于增强特征的尺度适应性。对于来自上层路径的特征与横向连接的特征,融合过程首先对各路特征进行加权,随后进行归一化处理,最终通过加法或拼接操作生成融合特征。

u012133341的博客 520

CodeForces - 977D:Divide by three, multiply by two

题目 Polycarp likes to play with numbers. He takes some integer number x, writes it down on the board, and then performs with it n−1 operations of the two kinds: divide the number x by 3 (x must be divisible by 3); multiply the number x by 2. After each op

Mr.RainsdRop的胡思乱想 351

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

CodeForces977D Divide by three, multiply by two

题目 Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, and then performs with it n−1n−1operations of the two kinds: divide the number xx by 33 (xx must...

weixin_30878501的博客 101

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

codeforces 解题报告 977D. Divide by three, multiply by two DFS

http://codeforces.com/problemset/problem/977/D解题思路:1.给一个序列,要求给它重新排序,规则要满足以下其中之一条件:前一个数是后一个数的三倍后一个数是前一个数的两倍2.序列长度只有100,并且保证答案一定存在,直接裸DFS爆搜答案import java.util.*; import static java.lang.System.exit; pu...

三生锁链 265

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Divide by three, multiply by two CodeForces - 977D(思维+map)

D. Divide by three, multiply by twotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp likes to play with numbers. He takes some integer numbe...

JiaYao的博客 549

Codeforces--977D--Divide by three, multiply by two

题目描述: Polycarp likes to play with numbers. He takes some integer number x, writes it down on the board, and then performs with it n−1 operations of the two kinds: divide the number x by 3 (x must be d...

猩猩是个好程序员的博客 291

CodeForces 977D Divide by three, multiply by two 拓扑排序

Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, and then performs with it n−1n−1 operations of the two kinds:divide the number xx by 33 (xx must be d...

这是一个博客 252

【Codeforces - 977D】Divide by three, multiply by two(思维构造)

题干: Polycarp likes to play with numbers. He takes some integer numberxx, writes it down on the board, and then performs with itn−1n−1operations of the two kinds: divide the numberxxby33(xxmu...

xuanweiace的博客 402

CodeForces - 977D D. Divide by three, multiply by two dfs路径打印

D. Divide by three, multiply by two time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp likes to play with numbers. He takes ...

pxlsdz的博客 600

Divide by three, multiply by two CodeForces - 977D (思维排序)

Polycarp likes to play with numbers. He takes some integer numberxx, writes it down on the board, and then performs with itn−1n−1operations of the two kinds: divide the numberxxby33(xxmust ...

weixin_30415113的博客 210

codeforces 977D Divide by three, multiply by two(DFS)

一、原题地址传送门二、大致题意    给出n个数,有两种操作。1、a[i]这个数能被3整除成为a[i+1]。2、a[i]×2=a[i+1].三、思路 裸的dfs.四、代码#include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstdlib&gt; #include&lt;cstring&gt; #include&lt;cmath&g...

Amove 491

Divide by three, multiply by two CodeForces - 977D (拓扑排序)

Divide by three, multiply by two Polycarp likes to play with numbers. He takes some integer numberx, writes it down on the board, and then performs with itn−1operations of the two kinds: divide...

SEVENY_的博客 407

CodeForces 977 D. Divide by three, multiply by two 除以三排序

题意:给定一个序列,重排,使后面一个数是前面一个数的2倍或者(1/3);思路:法一:建图,跑dfs;法二:一共有两种关系,题说一定有解,所以左边的一定是右边的数的3倍,或者除去3的倍数的因子以外的因子右边是左边的两倍;这样的话对于每个数除以三并记录个数,然后排序;法二代码:#include &lt;bits/stdc++.h&gt; using namespace std; typedef lon...

床前明月光 333

Codeforces 977D Divide by three, multiply by two(拓扑排序)

Polycarp likes to play with numbers. He takes some integer number xx, writes it down on the board, and then performs with it n−1n−1operations of the two kinds:divide the number xx by 33 (xx must be di...

qq_38586027的博客 334
上一篇: Codeforces 997B. Two-gram——————水题复习一下map
下一篇: Codefoces 977E - Cyclic Components——————dfs
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值